diff --git a/.build/common.mk b/.build/common.mk new file mode 100644 index 00000000..a2b899bd --- /dev/null +++ b/.build/common.mk @@ -0,0 +1,30 @@ +# Define the default target +.DEFAULT_GOAL := help + +# Include this in your Makefile using 'include common.mk' + +# ANSI colour codes for formatting (used for coloured output in help) +COLOUR_TARGET = \033[1;34m # Blue, bold +COLOUR_RESET = \033[0m # Reset colour + +# Automatically calculate the maximum target width (without colour) +TARGET_WIDTH := $(shell grep -Eh '^[a-zA-Z_-]+:.*?##' $(MAKEFILE_LIST) | awk -F':' '{print length($$1)}' | sort -nr | head -1) + +# Collect all targets from the Makefile and included files +PHONY_TARGETS := $(shell grep -Eh '^[a-zA-Z_-]+:.*?##' $(MAKEFILE_LIST) | awk -F':' '{print $$1}') # OR ... '{print $$1}' | sort -u) + +# Declare all the targets as phony +.PHONY: $(PHONY_TARGETS) + +# Help target that reads targets from all Makefiles listed in MAKEFILE_LIST +help: + @echo "Available targets:" + @grep -Eh '^[a-zA-Z_-]+:.*?##' $(MAKEFILE_LIST) | \ + #sort -u | \ + awk -v COLOUR_target="$(COLOUR_TARGET)" -v COLOUR_reset="$(COLOUR_RESET)" -v width=$(TARGET_WIDTH) '\ + BEGIN {FS = ":.*## "}; \ + { \ + target = $$1; \ + description = $$2; \ + printf "%s%-*s%s %s\n", COLOUR_target, width, target, COLOUR_reset, description \ + }' diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index ba7a2bbf..67d50ad4 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -2,12 +2,5 @@ "version": 1, "isRoot": true, "tools": { - "nbgv": { - "version": "3.6.139", - "commands": [ - "nbgv" - ], - "rollForward": false - } } } \ No newline at end of file diff --git a/.cspell.json b/.cspell.json new file mode 100644 index 00000000..bd07e8af --- /dev/null +++ b/.cspell.json @@ -0,0 +1,10 @@ +{ + "version": "0.2", + "language": "en-GB", + "words": [ + "kieronlanning" + ], + "ignorePaths": [ + "node_modules/**/*" + ] +} diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100644 index 00000000..8f5b9806 --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,3 @@ +npx --no -- commitlint --edit \ + +#exit 1 \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 00000000..592309f0 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +#npm test diff --git a/Makefile b/Makefile index e8482f02..e0ef07c1 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,26 @@ +include .build/common.mk + # Variables ROOT_FOLDER = src/ SOLUTION_FILE = $(ROOT_FOLDER)Purview.Telemetry.SourceGenerator.sln TEST_PROJECT = $(ROOT_FOLDER)Purview.Telemetry.SourceGenerator.sln CONFIGURATION = Release -PACK_VERSION = 1.0.12 +PACK_VERSION = 1.1.0 ARTIFACT_FOLDER = p:/sync-projects/.local-nuget/ # Targets -build: +build: ## Builds the project. dotnet build $(SOLUTION_FILE) --configuration $(CONFIGURATION) -test: +test: ## Runs the tests for the project. dotnet test $(TEST_PROJECT) --configuration $(CONFIGURATION) -pack: +pack: ## Packs the project into a nuget package using PACK_VERSION argument. dotnet pack -c $(CONFIGURATION) -o $(ARTIFACT_FOLDER) $(ROOT_FOLDER)Purview.Telemetry.SourceGenerator/Purview.Telemetry.SourceGenerator.csproj --property:Version=$(PACK_VERSION) --include-symbols -format: +format: ## Formats the code according to the rules of the src/.editorconfig file. dotnet format $(ROOT_FOLDER) act: act -P ubuntu-latest=-self-hosted - -.PHONY: build test diff --git a/commitlint.config.ts b/commitlint.config.ts new file mode 100644 index 00000000..3f5e287f --- /dev/null +++ b/commitlint.config.ts @@ -0,0 +1 @@ +export default { extends: ['@commitlint/config-conventional'] }; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..c3b31286 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,1253 @@ +{ + "name": "purview-telemetry-sourcegenerator", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "purview-telemetry-sourcegenerator", + "version": "1.0.0", + "license": "ISC", + "devDependencies": { + "@commitlint/cli": "^19.6.0", + "@commitlint/config-conventional": "^19.6.0", + "husky": "^9.1.7" + } + }, + "node_modules/@babel/code-frame": { + "version": "7.26.2", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.2.tgz", + "integrity": "sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-validator-identifier": "^7.25.9", + "js-tokens": "^4.0.0", + "picocolors": "^1.0.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-validator-identifier": { + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.9.tgz", + "integrity": "sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@commitlint/cli": { + "version": "19.6.0", + "resolved": "https://registry.npmjs.org/@commitlint/cli/-/cli-19.6.0.tgz", + "integrity": "sha512-v17BgGD9w5KnthaKxXnEg6KLq6DYiAxyiN44TpiRtqyW8NSq+Kx99mkEG8Qo6uu6cI5eMzMojW2muJxjmPnF8w==", + "dev": true, + "license": "MIT", + "dependencies": { + "@commitlint/format": "^19.5.0", + "@commitlint/lint": "^19.6.0", + "@commitlint/load": "^19.5.0", + "@commitlint/read": "^19.5.0", + "@commitlint/types": "^19.5.0", + "tinyexec": "^0.3.0", + "yargs": "^17.0.0" + }, + "bin": { + "commitlint": "cli.js" + }, + "engines": { + "node": ">=v18" + } + }, + "node_modules/@commitlint/config-conventional": { + "version": "19.6.0", + "resolved": "https://registry.npmjs.org/@commitlint/config-conventional/-/config-conventional-19.6.0.tgz", + "integrity": "sha512-DJT40iMnTYtBtUfw9ApbsLZFke1zKh6llITVJ+x9mtpHD08gsNXaIRqHTmwTZL3dNX5+WoyK7pCN/5zswvkBCQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@commitlint/types": "^19.5.0", + "conventional-changelog-conventionalcommits": "^7.0.2" + }, + "engines": { + "node": ">=v18" + } + }, + "node_modules/@commitlint/config-validator": { + "version": "19.5.0", + "resolved": "https://registry.npmjs.org/@commitlint/config-validator/-/config-validator-19.5.0.tgz", + "integrity": "sha512-CHtj92H5rdhKt17RmgALhfQt95VayrUo2tSqY9g2w+laAXyk7K/Ef6uPm9tn5qSIwSmrLjKaXK9eiNuxmQrDBw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@commitlint/types": "^19.5.0", + "ajv": "^8.11.0" + }, + "engines": { + "node": ">=v18" + } + }, + "node_modules/@commitlint/ensure": { + "version": "19.5.0", + "resolved": "https://registry.npmjs.org/@commitlint/ensure/-/ensure-19.5.0.tgz", + "integrity": "sha512-Kv0pYZeMrdg48bHFEU5KKcccRfKmISSm9MvgIgkpI6m+ohFTB55qZlBW6eYqh/XDfRuIO0x4zSmvBjmOwWTwkg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@commitlint/types": "^19.5.0", + "lodash.camelcase": "^4.3.0", + "lodash.kebabcase": "^4.1.1", + "lodash.snakecase": "^4.1.1", + "lodash.startcase": "^4.4.0", + "lodash.upperfirst": "^4.3.1" + }, + "engines": { + "node": ">=v18" + } + }, + "node_modules/@commitlint/execute-rule": { + "version": "19.5.0", + "resolved": "https://registry.npmjs.org/@commitlint/execute-rule/-/execute-rule-19.5.0.tgz", + "integrity": "sha512-aqyGgytXhl2ejlk+/rfgtwpPexYyri4t8/n4ku6rRJoRhGZpLFMqrZ+YaubeGysCP6oz4mMA34YSTaSOKEeNrg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=v18" + } + }, + "node_modules/@commitlint/format": { + "version": "19.5.0", + "resolved": "https://registry.npmjs.org/@commitlint/format/-/format-19.5.0.tgz", + "integrity": "sha512-yNy088miE52stCI3dhG/vvxFo9e4jFkU1Mj3xECfzp/bIS/JUay4491huAlVcffOoMK1cd296q0W92NlER6r3A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@commitlint/types": "^19.5.0", + "chalk": "^5.3.0" + }, + "engines": { + "node": ">=v18" + } + }, + "node_modules/@commitlint/is-ignored": { + "version": "19.6.0", + "resolved": "https://registry.npmjs.org/@commitlint/is-ignored/-/is-ignored-19.6.0.tgz", + "integrity": "sha512-Ov6iBgxJQFR9koOupDPHvcHU9keFupDgtB3lObdEZDroiG4jj1rzky60fbQozFKVYRTUdrBGICHG0YVmRuAJmw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@commitlint/types": "^19.5.0", + "semver": "^7.6.0" + }, + "engines": { + "node": ">=v18" + } + }, + "node_modules/@commitlint/lint": { + "version": "19.6.0", + "resolved": "https://registry.npmjs.org/@commitlint/lint/-/lint-19.6.0.tgz", + "integrity": "sha512-LRo7zDkXtcIrpco9RnfhOKeg8PAnE3oDDoalnrVU/EVaKHYBWYL1DlRR7+3AWn0JiBqD8yKOfetVxJGdEtZ0tg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@commitlint/is-ignored": "^19.6.0", + "@commitlint/parse": "^19.5.0", + "@commitlint/rules": "^19.6.0", + "@commitlint/types": "^19.5.0" + }, + "engines": { + "node": ">=v18" + } + }, + "node_modules/@commitlint/load": { + "version": "19.5.0", + "resolved": "https://registry.npmjs.org/@commitlint/load/-/load-19.5.0.tgz", + "integrity": "sha512-INOUhkL/qaKqwcTUvCE8iIUf5XHsEPCLY9looJ/ipzi7jtGhgmtH7OOFiNvwYgH7mA8osUWOUDV8t4E2HAi4xA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@commitlint/config-validator": "^19.5.0", + "@commitlint/execute-rule": "^19.5.0", + "@commitlint/resolve-extends": "^19.5.0", + "@commitlint/types": "^19.5.0", + "chalk": "^5.3.0", + "cosmiconfig": "^9.0.0", + "cosmiconfig-typescript-loader": "^5.0.0", + "lodash.isplainobject": "^4.0.6", + "lodash.merge": "^4.6.2", + "lodash.uniq": "^4.5.0" + }, + "engines": { + "node": ">=v18" + } + }, + "node_modules/@commitlint/message": { + "version": "19.5.0", + "resolved": "https://registry.npmjs.org/@commitlint/message/-/message-19.5.0.tgz", + "integrity": "sha512-R7AM4YnbxN1Joj1tMfCyBryOC5aNJBdxadTZkuqtWi3Xj0kMdutq16XQwuoGbIzL2Pk62TALV1fZDCv36+JhTQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=v18" + } + }, + "node_modules/@commitlint/parse": { + "version": "19.5.0", + "resolved": "https://registry.npmjs.org/@commitlint/parse/-/parse-19.5.0.tgz", + "integrity": "sha512-cZ/IxfAlfWYhAQV0TwcbdR1Oc0/r0Ik1GEessDJ3Lbuma/MRO8FRQX76eurcXtmhJC//rj52ZSZuXUg0oIX0Fw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@commitlint/types": "^19.5.0", + "conventional-changelog-angular": "^7.0.0", + "conventional-commits-parser": "^5.0.0" + }, + "engines": { + "node": ">=v18" + } + }, + "node_modules/@commitlint/read": { + "version": "19.5.0", + "resolved": "https://registry.npmjs.org/@commitlint/read/-/read-19.5.0.tgz", + "integrity": "sha512-TjS3HLPsLsxFPQj6jou8/CZFAmOP2y+6V4PGYt3ihbQKTY1Jnv0QG28WRKl/d1ha6zLODPZqsxLEov52dhR9BQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@commitlint/top-level": "^19.5.0", + "@commitlint/types": "^19.5.0", + "git-raw-commits": "^4.0.0", + "minimist": "^1.2.8", + "tinyexec": "^0.3.0" + }, + "engines": { + "node": ">=v18" + } + }, + "node_modules/@commitlint/resolve-extends": { + "version": "19.5.0", + "resolved": "https://registry.npmjs.org/@commitlint/resolve-extends/-/resolve-extends-19.5.0.tgz", + "integrity": "sha512-CU/GscZhCUsJwcKTJS9Ndh3AKGZTNFIOoQB2n8CmFnizE0VnEuJoum+COW+C1lNABEeqk6ssfc1Kkalm4bDklA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@commitlint/config-validator": "^19.5.0", + "@commitlint/types": "^19.5.0", + "global-directory": "^4.0.1", + "import-meta-resolve": "^4.0.0", + "lodash.mergewith": "^4.6.2", + "resolve-from": "^5.0.0" + }, + "engines": { + "node": ">=v18" + } + }, + "node_modules/@commitlint/rules": { + "version": "19.6.0", + "resolved": "https://registry.npmjs.org/@commitlint/rules/-/rules-19.6.0.tgz", + "integrity": "sha512-1f2reW7lbrI0X0ozZMesS/WZxgPa4/wi56vFuJENBmed6mWq5KsheN/nxqnl/C23ioxpPO/PL6tXpiiFy5Bhjw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@commitlint/ensure": "^19.5.0", + "@commitlint/message": "^19.5.0", + "@commitlint/to-lines": "^19.5.0", + "@commitlint/types": "^19.5.0" + }, + "engines": { + "node": ">=v18" + } + }, + "node_modules/@commitlint/to-lines": { + "version": "19.5.0", + "resolved": "https://registry.npmjs.org/@commitlint/to-lines/-/to-lines-19.5.0.tgz", + "integrity": "sha512-R772oj3NHPkodOSRZ9bBVNq224DOxQtNef5Pl8l2M8ZnkkzQfeSTr4uxawV2Sd3ui05dUVzvLNnzenDBO1KBeQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=v18" + } + }, + "node_modules/@commitlint/top-level": { + "version": "19.5.0", + "resolved": "https://registry.npmjs.org/@commitlint/top-level/-/top-level-19.5.0.tgz", + "integrity": "sha512-IP1YLmGAk0yWrImPRRc578I3dDUI5A2UBJx9FbSOjxe9sTlzFiwVJ+zeMLgAtHMtGZsC8LUnzmW1qRemkFU4ng==", + "dev": true, + "license": "MIT", + "dependencies": { + "find-up": "^7.0.0" + }, + "engines": { + "node": ">=v18" + } + }, + "node_modules/@commitlint/types": { + "version": "19.5.0", + "resolved": "https://registry.npmjs.org/@commitlint/types/-/types-19.5.0.tgz", + "integrity": "sha512-DSHae2obMSMkAtTBSOulg5X7/z+rGLxcXQIkg3OmWvY6wifojge5uVMydfhUvs7yQj+V7jNmRZ2Xzl8GJyqRgg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/conventional-commits-parser": "^5.0.0", + "chalk": "^5.3.0" + }, + "engines": { + "node": ">=v18" + } + }, + "node_modules/@types/conventional-commits-parser": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@types/conventional-commits-parser/-/conventional-commits-parser-5.0.1.tgz", + "integrity": "sha512-7uz5EHdzz2TqoMfV7ee61Egf5y6NkcO4FB/1iCCQnbeiI1F3xzv3vK5dBCXUCLQgGYS+mUeigK1iKQzvED+QnQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/node": { + "version": "22.10.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.1.tgz", + "integrity": "sha512-qKgsUwfHZV2WCWLAnVP1JqnpE6Im6h3Y0+fYgMTasNQ7V++CBX5OT1as0g0f+OyubbFqhf6XVNIsmN4IIhEgGQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.20.0" + } + }, + "node_modules/ajv": { + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz", + "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "license": "MIT", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true, + "license": "Python-2.0" + }, + "node_modules/array-ify": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/array-ify/-/array-ify-1.0.0.tgz", + "integrity": "sha512-c5AMf34bKdvPhQ7tBGhqkgKNUzMr4WUs+WDtC2ZUGOUncbxKMTvqxYctiseW3+L4bA8ec+GcZ6/A/FW4m8ukng==", + "dev": true, + "license": "MIT" + }, + "node_modules/callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/chalk": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", + "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/cliui": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "dev": true, + "license": "ISC", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true, + "license": "MIT" + }, + "node_modules/compare-func": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/compare-func/-/compare-func-2.0.0.tgz", + "integrity": "sha512-zHig5N+tPWARooBnb0Zx1MFcdfpyJrfTJ3Y5L+IFvUm8rM74hHz66z0gw0x4tijh5CorKkKUCnW82R2vmpeCRA==", + "dev": true, + "license": "MIT", + "dependencies": { + "array-ify": "^1.0.0", + "dot-prop": "^5.1.0" + } + }, + "node_modules/conventional-changelog-angular": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/conventional-changelog-angular/-/conventional-changelog-angular-7.0.0.tgz", + "integrity": "sha512-ROjNchA9LgfNMTTFSIWPzebCwOGFdgkEq45EnvvrmSLvCtAw0HSmrCs7/ty+wAeYUZyNay0YMUNYFTRL72PkBQ==", + "dev": true, + "license": "ISC", + "dependencies": { + "compare-func": "^2.0.0" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/conventional-changelog-conventionalcommits": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/conventional-changelog-conventionalcommits/-/conventional-changelog-conventionalcommits-7.0.2.tgz", + "integrity": "sha512-NKXYmMR/Hr1DevQegFB4MwfM5Vv0m4UIxKZTTYuD98lpTknaZlSRrDOG4X7wIXpGkfsYxZTghUN+Qq+T0YQI7w==", + "dev": true, + "license": "ISC", + "dependencies": { + "compare-func": "^2.0.0" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/conventional-commits-parser": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/conventional-commits-parser/-/conventional-commits-parser-5.0.0.tgz", + "integrity": "sha512-ZPMl0ZJbw74iS9LuX9YIAiW8pfM5p3yh2o/NbXHbkFuZzY5jvdi5jFycEOkmBW5H5I7nA+D6f3UcsCLP2vvSEA==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-text-path": "^2.0.0", + "JSONStream": "^1.3.5", + "meow": "^12.0.1", + "split2": "^4.0.0" + }, + "bin": { + "conventional-commits-parser": "cli.mjs" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/cosmiconfig": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-9.0.0.tgz", + "integrity": "sha512-itvL5h8RETACmOTFc4UfIyB2RfEHi71Ax6E/PivVxq9NseKbOWpeyHEOIbmAw1rs8Ak0VursQNww7lf7YtUwzg==", + "dev": true, + "license": "MIT", + "dependencies": { + "env-paths": "^2.2.1", + "import-fresh": "^3.3.0", + "js-yaml": "^4.1.0", + "parse-json": "^5.2.0" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/d-fischer" + }, + "peerDependencies": { + "typescript": ">=4.9.5" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/cosmiconfig-typescript-loader": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/cosmiconfig-typescript-loader/-/cosmiconfig-typescript-loader-5.1.0.tgz", + "integrity": "sha512-7PtBB+6FdsOvZyJtlF3hEPpACq7RQX6BVGsgC7/lfVXnKMvNCu/XY3ykreqG5w/rBNdu2z8LCIKoF3kpHHdHlA==", + "dev": true, + "license": "MIT", + "dependencies": { + "jiti": "^1.21.6" + }, + "engines": { + "node": ">=v16" + }, + "peerDependencies": { + "@types/node": "*", + "cosmiconfig": ">=8.2", + "typescript": ">=4" + } + }, + "node_modules/dargs": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/dargs/-/dargs-8.1.0.tgz", + "integrity": "sha512-wAV9QHOsNbwnWdNW2FYvE1P56wtgSbM+3SZcdGiWQILwVjACCXDCI3Ai8QlCjMDB8YK5zySiXZYBiwGmNY3lnw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/dot-prop": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-5.3.0.tgz", + "integrity": "sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-obj": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true, + "license": "MIT" + }, + "node_modules/env-paths": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz", + "integrity": "sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/error-ex": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", + "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-arrayish": "^0.2.1" + } + }, + "node_modules/escalade": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", + "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/fast-uri": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.0.3.tgz", + "integrity": "sha512-aLrHthzCjH5He4Z2H9YZ+v6Ujb9ocRuW6ZzkJQOrTxleEijANq4v1TsaPaVG1PZcuurEzrLcWRyYBYXD5cEiaw==", + "dev": true, + "license": "BSD-3-Clause" + }, + "node_modules/find-up": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-7.0.0.tgz", + "integrity": "sha512-YyZM99iHrqLKjmt4LJDj58KI+fYyufRLBSYcqycxf//KpBk9FoewoGX0450m9nB44qrZnovzC2oeP5hUibxc/g==", + "dev": true, + "license": "MIT", + "dependencies": { + "locate-path": "^7.2.0", + "path-exists": "^5.0.0", + "unicorn-magic": "^0.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "dev": true, + "license": "ISC", + "engines": { + "node": "6.* || 8.* || >= 10.*" + } + }, + "node_modules/git-raw-commits": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/git-raw-commits/-/git-raw-commits-4.0.0.tgz", + "integrity": "sha512-ICsMM1Wk8xSGMowkOmPrzo2Fgmfo4bMHLNX6ytHjajRJUqvHOw/TFapQ+QG75c3X/tTDDhOSRPGC52dDbNM8FQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "dargs": "^8.0.0", + "meow": "^12.0.1", + "split2": "^4.0.0" + }, + "bin": { + "git-raw-commits": "cli.mjs" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/global-directory": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/global-directory/-/global-directory-4.0.1.tgz", + "integrity": "sha512-wHTUcDUoZ1H5/0iVqEudYW4/kAlN5cZ3j/bXn0Dpbizl9iaUVeWSHqiOjsgk6OW2bkLclbBjzewBz6weQ1zA2Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "ini": "4.1.1" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/husky": { + "version": "9.1.7", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.7.tgz", + "integrity": "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==", + "dev": true, + "license": "MIT", + "bin": { + "husky": "bin.js" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, + "node_modules/import-fresh": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", + "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", + "dev": true, + "license": "MIT", + "dependencies": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/import-fresh/node_modules/resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/import-meta-resolve": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/import-meta-resolve/-/import-meta-resolve-4.1.0.tgz", + "integrity": "sha512-I6fiaX09Xivtk+THaMfAwnA3MVA5Big1WHF1Dfx9hFuvNIWpXnorlkzhcQf6ehrqQiiZECRt1poOAkPmer3ruw==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/ini": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ini/-/ini-4.1.1.tgz", + "integrity": "sha512-QQnnxNyfvmHFIsj7gkPcYymR8Jdw/o7mp5ZFihxn6h8Ci6fh3Dx4E1gPjpQEpIuPo9XVNY/ZUwh4BPMjGyL01g==", + "dev": true, + "license": "ISC", + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, + "node_modules/is-arrayish": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", + "integrity": "sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==", + "dev": true, + "license": "MIT" + }, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/is-obj": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz", + "integrity": "sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/is-text-path": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-text-path/-/is-text-path-2.0.0.tgz", + "integrity": "sha512-+oDTluR6WEjdXEJMnC2z6A4FRwFoYuvShVVEGsS7ewc0UTi2QtAKMDJuL4BDEVt+5T7MjFo12RP8ghOM75oKJw==", + "dev": true, + "license": "MIT", + "dependencies": { + "text-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/jiti": { + "version": "1.21.6", + "resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.6.tgz", + "integrity": "sha512-2yTgeWTWzMWkHu6Jp9NKgePDaYHbntiwvYuuJLbbN9vl7DC9DvXKOB2BC3ZZ92D3cvV/aflH0osDfwpHepQ53w==", + "dev": true, + "license": "MIT", + "bin": { + "jiti": "bin/jiti.js" + } + }, + "node_modules/js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dev": true, + "license": "MIT", + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, + "node_modules/json-parse-even-better-errors": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", + "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", + "dev": true, + "license": "MIT" + }, + "node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "dev": true, + "license": "MIT" + }, + "node_modules/jsonparse": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz", + "integrity": "sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==", + "dev": true, + "engines": [ + "node >= 0.2.0" + ], + "license": "MIT" + }, + "node_modules/JSONStream": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz", + "integrity": "sha512-E+iruNOY8VV9s4JEbe1aNEm6MiszPRr/UfcHMz0TQh1BXSxHK+ASV1R6W4HpjBhSeS+54PIsAMCBmwD06LLsqQ==", + "dev": true, + "license": "(MIT OR Apache-2.0)", + "dependencies": { + "jsonparse": "^1.2.0", + "through": ">=2.2.7 <3" + }, + "bin": { + "JSONStream": "bin.js" + }, + "engines": { + "node": "*" + } + }, + "node_modules/lines-and-columns": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", + "integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==", + "dev": true, + "license": "MIT" + }, + "node_modules/locate-path": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-7.2.0.tgz", + "integrity": "sha512-gvVijfZvn7R+2qyPX8mAuKcFGDf6Nc61GdvGafQsHL0sBIxfKzA+usWn4GFC/bk+QdwPUD4kWFJLhElipq+0VA==", + "dev": true, + "license": "MIT", + "dependencies": { + "p-locate": "^6.0.0" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/lodash.camelcase": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", + "integrity": "sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==", + "dev": true, + "license": "MIT" + }, + "node_modules/lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==", + "dev": true, + "license": "MIT" + }, + "node_modules/lodash.kebabcase": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz", + "integrity": "sha512-N8XRTIMMqqDgSy4VLKPnJ/+hpGZN+PHQiJnSenYqPaVV/NCqEogTnAdZLQiGKhxX+JCs8waWq2t1XHWKOmlY8g==", + "dev": true, + "license": "MIT" + }, + "node_modules/lodash.merge": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/lodash.mergewith": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.mergewith/-/lodash.mergewith-4.6.2.tgz", + "integrity": "sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/lodash.snakecase": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz", + "integrity": "sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==", + "dev": true, + "license": "MIT" + }, + "node_modules/lodash.startcase": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/lodash.startcase/-/lodash.startcase-4.4.0.tgz", + "integrity": "sha512-+WKqsK294HMSc2jEbNgpHpd0JfIBhp7rEV4aqXWqFr6AlXov+SlcgB1Fv01y2kGe3Gc8nMW7VA0SrGuSkRfIEg==", + "dev": true, + "license": "MIT" + }, + "node_modules/lodash.uniq": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz", + "integrity": "sha512-xfBaXQd9ryd9dlSDvnvI0lvxfLJlYAZzXomUYzLKtUeOQvOP5piqAWuGtrhWeqaXK9hhoM/iyJc5AV+XfsX3HQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/lodash.upperfirst": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/lodash.upperfirst/-/lodash.upperfirst-4.3.1.tgz", + "integrity": "sha512-sReKOYJIJf74dhJONhU4e0/shzi1trVbSWDOhKYE5XV2O+H7Sb2Dihwuc7xWxVl+DgFPyTqIN3zMfT9cq5iWDg==", + "dev": true, + "license": "MIT" + }, + "node_modules/meow": { + "version": "12.1.1", + "resolved": "https://registry.npmjs.org/meow/-/meow-12.1.1.tgz", + "integrity": "sha512-BhXM0Au22RwUneMPwSCnyhTOizdWoIEPU9sp0Aqa1PnDMR5Wv2FGXYDjuzJEIX+Eo2Rb8xuYe5jrnm5QowQFkw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=16.10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/p-limit": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-4.0.0.tgz", + "integrity": "sha512-5b0R4txpzjPWVw/cXXUResoD4hb6U/x9BH08L7nw+GN1sezDzPdxeRvpc9c433fZhBan/wusjbCsqwqm4EIBIQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "yocto-queue": "^1.0.0" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-6.0.0.tgz", + "integrity": "sha512-wPrq66Llhl7/4AGC6I+cqxT07LhXvWL08LNXz1fENOw0Ap4sRZZ/gZpTTJ5jpurzzzfS2W/Ge9BY3LgLjCShcw==", + "dev": true, + "license": "MIT", + "dependencies": { + "p-limit": "^4.0.0" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/parent-module": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", + "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, + "license": "MIT", + "dependencies": { + "callsites": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/parse-json": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.2.0.tgz", + "integrity": "sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/code-frame": "^7.0.0", + "error-ex": "^1.3.1", + "json-parse-even-better-errors": "^2.3.0", + "lines-and-columns": "^1.1.6" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/path-exists": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-5.0.0.tgz", + "integrity": "sha512-RjhtfwJOxzcFmNOi6ltcbcu4Iu+FL3zEj83dk4kAS+fVpTxXLO1b38RvJgT/0QwvV/L3aY9TAnyv0EOqW4GoMQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + } + }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "dev": true, + "license": "ISC" + }, + "node_modules/require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/resolve-from": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz", + "integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/semver": { + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/split2": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", + "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">= 10.x" + } + }, + "node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "license": "MIT", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/text-extensions": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/text-extensions/-/text-extensions-2.4.0.tgz", + "integrity": "sha512-te/NtwBwfiNRLf9Ijqx3T0nlqZiQ2XrrtBvu+cLL8ZRrGkO0NHTug8MYFKyoSrv/sHTaSKfilUkizV6XhxMJ3g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/through": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", + "integrity": "sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==", + "dev": true, + "license": "MIT" + }, + "node_modules/tinyexec": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-0.3.1.tgz", + "integrity": "sha512-WiCJLEECkO18gwqIp6+hJg0//p23HXp4S+gGtAKu3mI2F2/sXC4FvHvXvB0zJVVaTPhx1/tOwdbRsa1sOBIKqQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/typescript": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz", + "integrity": "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "6.20.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz", + "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==", + "dev": true, + "license": "MIT" + }, + "node_modules/unicorn-magic": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/unicorn-magic/-/unicorn-magic-0.1.0.tgz", + "integrity": "sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/y18n": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=10" + } + }, + "node_modules/yargs": { + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "dev": true, + "license": "MIT", + "dependencies": { + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/yargs-parser": { + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=12" + } + }, + "node_modules/yocto-queue": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.1.1.tgz", + "integrity": "sha512-b4JR1PFR10y1mKjhHY9LaGo6tmrgjit7hxVIeAmyMw3jegXR4dhYqLaQF5zMXZxY7tLpMyJeLjr1C4rLmkVe8g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..e26365a1 --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "purview-telemetry-sourcegenerator", + "version": "1.0.0", + "description": "Generates [ActivitySource](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.activitysource), [High-performance logging](https://learn.microsoft.com/en-us/dotnet/core/extensions/high-performance-logging) and [Metrics](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.metrics) based on methods on an interface, enabling fast iteration cycles, dependency injection and substitutes for testing.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/purview-dev/purview-telemetry-sourcegenerator.git" + }, + "author": "Kieron Lanning", + "license": "ISC", + "bugs": { + "url": "https://github.com/purview-dev/purview-telemetry-sourcegenerator/issues" + }, + "homepage": "https://github.com/purview-dev/purview-telemetry-sourcegenerator#readme", + "devDependencies": { + "@commitlint/cli": "^19.6.0", + "@commitlint/config-conventional": "^19.6.0", + "husky": "^9.1.7" + } +} diff --git a/src/.build-system/msbuild/variables.props b/src/.build-system/BuildVariables.props similarity index 88% rename from src/.build-system/msbuild/variables.props rename to src/.build-system/BuildVariables.props index d64bbb58..7d839c6b 100644 --- a/src/.build-system/msbuild/variables.props +++ b/src/.build-system/BuildVariables.props @@ -1,47 +1,37 @@ - - + - true false <_CsProjContent>$([System.IO.File]::ReadAllText(`$(MSBuildProjectFullPath)`)) - - $([System.Text.RegularExpressions.Regex]::IsMatch(`$(_CsProjContent))`, `(?s-i)(?:^|\s|>)(?s-i)(?:^|\s|>)<\s*(?:Project|Import)\s(?:[^>]*?)\s?Sdk\s*="(?<sdkproj>.*?)"`)) $([System.Text.RegularExpressions.Regex]::Match(`$(_CsProjContent))`, `(?s-i)(?:^|\s|>)(?s-i)(?:^|\s|>)<\s*(?:Project|Import)\s(?:[^>]*?)\s?Sdk\s*="(?<sdkproj>.*?)"`).Groups['sdkproj'].Value) - - <_CsProjContent>$([System.IO.File]::ReadAllText(`$(MSBuildProjectFullPath)`)) $(MSBuildThisFileDirectory)Properties/ $([System.Text.RegularExpressions.Regex]::Match($(MSBuildProjectName), `^.*\.([\w|_]\w*)Tests?$`).get_Groups().get_Item(1).ToString()) - - - - + + $(MSBuildProjectName.Replace('.Core', '')) - + $(MSBuildProjectName.Replace('.Shared', '')) - true $(MSBuildProjectName.Replace('.Core.$(TestingType)Tests', '').Replace('.$(TestingType)Tests', '')) - + $(MSBuildProjectName.Replace('.Shared.$(TestingType)Tests', '').Replace('.$(TestingType)Tests', '')) - @@ -62,7 +52,6 @@ - $(MSBuildProjectName).%(TestType.Identity)Tests - - diff --git a/src/.build-system/Directory.Build.props b/src/.build-system/Directory.Build.props index f4732066..414c04f2 100644 --- a/src/.build-system/Directory.Build.props +++ b/src/.build-system/Directory.Build.props @@ -1,27 +1,20 @@  - - - + + net9.0 + 13.0 - net8.0 - - true - true - true - + enable + enable true - true - false - - 12.0 - - enable - enable + true + true + true + false true true @@ -43,55 +36,58 @@ false false - - - - - - - - - - + + + + <_Parameter1>"DynamicProxyGenAssembly2" + + + <_Parameter1>"KJL Solutions Ltd." + + + <_Parameter1>"KJL Solutions Ltd. © 2024 | All Rights Reserved" + + + Kieron Lanning + KJL Solutions Ltd. + KJL Solutions Ltd., 2024 | All rights reserved. + https://github.com/purview-dev/purview-telemetry-sourcegenerator/ + + - true $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - true + true snupkg - - all runtime; build; native; contentfiles; analyzers - - $(NoWarn);CA1707 true @@ -106,30 +102,28 @@ False False - - + + <_Parameter1>Category <_Parameter2>$(TestingType) - - - + - - + + @@ -148,5 +142,4 @@ - diff --git a/src/.build-system/msbuild/Properties/AssemblyInfo_Shared.cs b/src/.build-system/msbuild/Properties/AssemblyInfo_Shared.cs deleted file mode 100644 index 1ca5dabd..00000000 --- a/src/.build-system/msbuild/Properties/AssemblyInfo_Shared.cs +++ /dev/null @@ -1,7 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] - -[assembly: AssemblyCompany("Purview Consultancy")] -[assembly: AssemblyCopyright("KJL Solutions Ltd. © 2024 | All rights reserved.")] diff --git a/src/.build-system/msbuild/Properties/AssemblyInfo_SharedTesting.cs b/src/.build-system/msbuild/Properties/AssemblyInfo_SharedTesting.cs deleted file mode 100644 index 2c336f58..00000000 --- a/src/.build-system/msbuild/Properties/AssemblyInfo_SharedTesting.cs +++ /dev/null @@ -1,5 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; - -[assembly: ExcludeFromCodeCoverage] -[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] diff --git a/src/.build-system/msbuild/nuget-packable-default.props b/src/.build-system/msbuild/nuget-packable-default.props deleted file mode 100644 index d8fd8925..00000000 --- a/src/.build-system/msbuild/nuget-packable-default.props +++ /dev/null @@ -1,12 +0,0 @@ - - - - - Kieron Lanning - KJL Solutions Ltd. - KJL Solutions Ltd., 2024 | All rights reserved. - https://github.com/purview-dev/purview-telemetry-sourcegenerator/ - - - - diff --git a/src/.build-system/xunit/GeneratorBaseTest.cs b/src/.build-system/xunit/GeneratorBaseTest.cs deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 8b20675f..514ebf50 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,5 +1,4 @@  - @@ -7,5 +6,4 @@ $(NoWarn);CA1031; logging;source-generator;high-performance-logging;dotnet;aspnet;otel;open-telemetry;traces;tracing;metrics;events;distributed-traces;distributed-tracing; - diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets index 9408fb11..24a58ece 100644 --- a/src/Directory.Build.targets +++ b/src/Directory.Build.targets @@ -1,5 +1,3 @@  - - diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index aa15360e..ba97be40 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -1,7 +1,7 @@  true - 4.10.0 + 4.12.0 @@ -10,21 +10,22 @@ - - - + + + - - - - - + + + + + + - - - - - + + + + + \ No newline at end of file diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.BasicEventGen.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.BasicEventGen.cs index dba8b072..45a659ad 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.BasicEventGen.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.BasicEventGen.cs @@ -3,7 +3,7 @@ partial class TelemetrySourceGeneratorActivityTests { [Fact] - public async Task Generate_GivenBasicEventWithActivityParameter_GeneratesActivity() + public async Task Generate_GivenBasicEventWithActivityParameter_GeneratesEvent() { // Arrange const string basicActivity = @" @@ -31,7 +31,7 @@ public interface ITestActivities } [Fact] - public async Task Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity() + public async Task Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent() { // Arrange const string basicActivity = @" @@ -57,4 +57,147 @@ public interface ITestActivities // Assert await TestHelpers.Verify(generationResult); } + + [Fact] + public async Task Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent() + { + // Arrange + const string basicActivity = @" +using Purview.Telemetry.Activities; +using System.Diagnostics; + +namespace Testing; + +[ActivitySource(""testing-activity-source"")] +public interface ITestActivities +{ + [Activity] + System.Diagnostics.Activity? Activity(); + + [Event(ActivityStatusCode.Ok)] + void Event(Activity? activity); +} +"; + + // Act + var generationResult = await GenerateAsync(basicActivity); + + // Assert + await TestHelpers.Verify(generationResult); + } + + [Fact] + public async Task Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent() + { + // Arrange + const string basicActivity = @" +using Purview.Telemetry.Activities; +using System.Diagnostics; + +namespace Testing; + +[ActivitySource(""testing-activity-source"")] +public interface ITestActivities +{ + [Activity] + System.Diagnostics.Activity? Activity(); + + [Event(ActivityStatusCode.Error)] + void Event(Activity? activity); +} +"; + + // Act + var generationResult = await GenerateAsync(basicActivity); + + // Assert + await TestHelpers.Verify(generationResult); + } + + [Fact] + public async Task Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent() + { + // Arrange + const string basicActivity = @" +using Purview.Telemetry.Activities; +using System.Diagnostics; + +namespace Testing; + +[ActivitySource(""testing-activity-source"")] +public interface ITestActivities +{ + [Activity] + System.Diagnostics.Activity? Activity(); + + [Event(ActivityStatusCode.Error)] + void Event(Activity? activity, Exception exception); +} +"; + + // Act + var generationResult = await GenerateAsync(basicActivity); + + // Assert + await TestHelpers.Verify(generationResult); + } + + [Fact] + public async Task Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent() + { + // Arrange + const string basicActivity = @" +using Purview.Telemetry.Activities; +using System.Diagnostics; + +namespace Testing; + +[ActivitySource(""testing-activity-source"")] +public interface ITestActivities +{ + [Activity] + System.Diagnostics.Activity? Activity(); + + [Event(ActivityStatusCode.Error, StatusDescription = ""This is a Test"")] + void Event(Activity? activity, Exception exception); +} +"; + + // Act + var generationResult = await GenerateAsync(basicActivity); + + // Assert + await TestHelpers.Verify(generationResult); + } + + [Fact] + public async Task Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent() + { + // Arrange + const string basicActivity = @" +using Purview.Telemetry.Activities; +using System.Diagnostics; + +namespace Testing; + +[ActivitySource(""testing-activity-source"")] +public interface ITestActivities +{ + [Activity] + System.Diagnostics.Activity? Activity(); + + [Event(ActivityStatusCode.Error)] + void Event(Activity? activity, [StatusDescription]string? statusDescription); + + [Event(ActivityStatusCode.Error)] + void Event2(Activity? activity, [StatusDescription]string statusDescription_another); +} +"; + + // Act + var generationResult = await GenerateAsync(basicActivity); + + // Assert + await TestHelpers.Verify(generationResult); + } } diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.cs index d942408a..c1c7e40f 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.cs @@ -34,7 +34,7 @@ public interface ITestActivities // Assert await TestHelpers.Verify(generationResult, c => c .ScrubInlineGuids() - .UseHashedParameters(parameterType) + .UseParameters(parameterType) ); } } diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.BasicGen.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.BasicGen.cs index b0618db5..b8f6b6ec 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.BasicGen.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.BasicGen.cs @@ -70,7 +70,7 @@ public interface ITestLogger {{ var generationResult = await GenerateAsync(basicLogger); // Assert - await TestHelpers.Verify(generationResult, c => c.ScrubInlineGuids().UseHashedParameters(level)); + await TestHelpers.Verify(generationResult, c => c.ScrubInlineGuids().UseParameters(level)); } [Fact] diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.LogEntryAttribute.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.LogEntryAttribute.cs index 8cbc81e6..af2609b9 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.LogEntryAttribute.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.LogEntryAttribute.cs @@ -23,7 +23,7 @@ public interface ITestLogger {{ var generationResult = await GenerateAsync(basicLogger); // Assert - await TestHelpers.Verify(generationResult, c => c.UseHashedParameters(logTargetName)); + await TestHelpers.Verify(generationResult, c => c.UseParameters(logTargetName)); } [Theory] @@ -53,7 +53,7 @@ public interface ITestLogger {{ var generationResult = await GenerateAsync(basicLogger); // Assert - await TestHelpers.Verify(generationResult, c => c.UseHashedParameters(prefixType, logTargetName)); + await TestHelpers.Verify(generationResult, c => c.UseParameters(prefixType, logTargetName)); } public static TheoryData GetPrefixAndEntryNames() diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.Nested.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.Nested.cs index 9612b4e0..3b4eb724 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.Nested.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.Nested.cs @@ -24,7 +24,7 @@ public interface ITestLogger {{ var generationResult = await GenerateAsync(basicLogger); // Assert - await TestHelpers.Verify(generationResult, c => c.ScrubInlineGuids().UseHashedParameters(@namespace)); + await TestHelpers.Verify(generationResult, c => c.ScrubInlineGuids().UseParameters(@namespace)); } [Theory] @@ -51,7 +51,7 @@ public interface ITestLogger {{ var generationResult = await GenerateAsync(basicLogger); // Assert - await TestHelpers.Verify(generationResult, c => c.ScrubInlineGuids().UseHashedParameters(@namespace)); + await TestHelpers.Verify(generationResult, c => c.ScrubInlineGuids().UseParameters(@namespace)); } [Theory] @@ -82,6 +82,6 @@ public interface ITestLogger {{ var generationResult = await GenerateAsync(basicLogger); // Assert - await TestHelpers.Verify(generationResult, c => c.ScrubInlineGuids().UseHashedParameters(@namespace)); + await TestHelpers.Verify(generationResult, c => c.ScrubInlineGuids().UseParameters(@namespace)); } } diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.SpecificLogAttribute.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.SpecificLogAttribute.cs index a119c068..08a9e01d 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.SpecificLogAttribute.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.SpecificLogAttribute.cs @@ -24,7 +24,7 @@ public interface ITestLogger var generationResult = await GenerateAsync(basicLogger); // Assert - await TestHelpers.Verify(generationResult, c => c.UseHashedParameters(attribute)); + await TestHelpers.Verify(generationResult, c => c.UseParameters(attribute)); } [Theory] @@ -64,7 +64,7 @@ public interface ITestLogger var generationResult = await GenerateAsync(basicLogger); // Assert - await TestHelpers.Verify(generationResult, c => c.UseHashedParameters(attribute)); + await TestHelpers.Verify(generationResult, c => c.UseParameters(attribute)); } public static TheoryData SpecificLogAttributeTypes diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.cs index 0af7dbd6..3f29bfdb 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.cs @@ -26,7 +26,7 @@ public interface ITestLogger {{ // Assert await TestHelpers.Verify(generationResult, c => c .ScrubInlineGuids() - .UseHashedParameters(parameterType) + .UseParameters(parameterType) ); } } diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Metrics/TelemetrySourceGeneratorMetricsTests.NameUnitsDescription.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Metrics/TelemetrySourceGeneratorMetricsTests.NameUnitsDescription.cs index 9a74804e..6afa7083 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Metrics/TelemetrySourceGeneratorMetricsTests.NameUnitsDescription.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Metrics/TelemetrySourceGeneratorMetricsTests.NameUnitsDescription.cs @@ -25,7 +25,7 @@ public interface ITestMetrics {{ var generationResult = await GenerateAsync(basicMetric); // Assert - await TestHelpers.Verify(generationResult, s => s.UseHashedParameters(attribute, measurementParameter)); + await TestHelpers.Verify(generationResult, s => s.UseParameters(attribute, measurementParameter)); } public static TheoryData NameUnitsDescriptorData diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Metrics/TelemetrySourceGeneratorMetricsTests.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Metrics/TelemetrySourceGeneratorMetricsTests.cs index 2496ecf6..6bafd594 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Metrics/TelemetrySourceGeneratorMetricsTests.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Metrics/TelemetrySourceGeneratorMetricsTests.cs @@ -49,7 +49,7 @@ public interface ITestMetrics // Assert await TestHelpers.Verify(generationResult, c => c .ScrubInlineGuids() - .UseHashedParameters(parameterType) + .UseParameters(parameterType) ); } } diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Purview.Telemetry.SourceGenerator.IntegrationTests.csproj b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Purview.Telemetry.SourceGenerator.IntegrationTests.csproj index 048f7f1f..42721d6b 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Purview.Telemetry.SourceGenerator.IntegrationTests.csproj +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Purview.Telemetry.SourceGenerator.IntegrationTests.csproj @@ -1,5 +1,4 @@  - @@ -9,6 +8,10 @@ + + + + @@ -20,21 +23,13 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..31ef92b5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,88 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity(string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("intparam", intParam); + activityActivity.SetTag("boolparam", boolParam); + } + + if (activityActivity != null) + { + activityActivity.SetBaggage("stringparam", stringParam); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("intparam", intParam); + tagsCollectionEvent.Add("boolparam", boolParam); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + + activity.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCoreDIExtension.DependencyInjection.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCoreDIExtension.DependencyInjection.g.verified.cs new file mode 100644 index 00000000..c132ae74 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCoreDIExtension.DependencyInjection.g.verified.cs @@ -0,0 +1,27 @@ +//HintName: Testing.TestActivitiesCoreDIExtension.DependencyInjection.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Microsoft.Extensions.DependencyInjection +{ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + static class TestActivitiesCoreDIExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static public Microsoft.Extensions.DependencyInjection.IServiceCollection AddTestActivities(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) + { + return services.AddSingleton(); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..3d92ac8f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,87 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Context(System.Diagnostics.Activity activityParameter, string? stringParam, int? intParam, bool? boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activityParameter != null) + { + activityParameter.SetTag("intparam", intParam); + activityParameter.SetTag("boolparam", boolParam); + activityParameter.SetBaggage("stringparam", stringParam); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ContextWithNullableParams(System.Diagnostics.Activity? activityParameter, string? stringParam, int? intParam, bool? boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activityParameter != null) + { + activityParameter.SetTag("intparam", intParam); + activityParameter.SetTag("boolparam", boolParam); + activityParameter.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..4e0f0107 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,91 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity Context(System.Diagnostics.Activity activityParameter, string? stringParam, int? intParam, bool? boolParam) + { + if (!_activitySource.HasListeners()) + { + return null!; + } + + if (activityParameter != null) + { + activityParameter.SetTag("intparam", intParam); + activityParameter.SetTag("boolparam", boolParam); + activityParameter.SetBaggage("stringparam", stringParam); + } + + return activityParameter; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? ContextWithNullableParams(System.Diagnostics.Activity? activityParameter, string? stringParam, int? intParam, bool? boolParam) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + if (activityParameter != null) + { + activityParameter.SetTag("intparam", intParam); + activityParameter.SetTag("boolparam", boolParam); + activityParameter.SetBaggage("stringparam", stringParam); + } + + return activityParameter; + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..acf2ccb4 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,91 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity Context(System.Diagnostics.Activity? activity, string? stringParam, int? intParam, bool? boolParam) + { + if (!_activitySource.HasListeners()) + { + return null!; + } + + if (activity != null) + { + activity.SetTag("intparam", intParam); + activity.SetTag("boolparam", boolParam); + activity.SetBaggage("stringparam", stringParam); + } + + return activity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? ContextWithNullableParams(System.Diagnostics.Activity? activity, string? stringParam, int? intParam, bool? boolParam) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + if (activity != null) + { + activity.SetTag("intparam", intParam); + activity.SetTag("boolparam", boolParam); + activity.SetBaggage("stringparam", stringParam); + } + + return activity; + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..4d81ba0a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,73 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity Context(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return null!; + } + + if (activity != null) + { + activity.SetTag("intparam", intParam); + activity.SetTag("boolparam", boolParam); + activity.SetBaggage("stringparam", stringParam); + } + + return activity; + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..a2fc35b0 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,91 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity Context(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return null!; + } + + if (activity != null) + { + activity.SetTag("intparam", intParam); + activity.SetTag("boolparam", boolParam); + activity.SetBaggage("stringparam", stringParam); + } + + return activity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? ContextWithNullableReturnActivity(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + if (activity != null) + { + activity.SetTag("intparam", intParam); + activity.SetTag("boolparam", boolParam); + activity.SetBaggage("stringparam", stringParam); + } + + return activity; + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..c6242fc4 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Context(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + activity.SetTag("intparam", intParam); + activity.SetTag("boolparam", boolParam); + activity.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..b29913a8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,77 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, System.Exception exception) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + + RecordExceptionInternal(activity: activity, exception: exception, escape: true); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + + activity.SetStatus(System.Diagnostics.ActivityStatusCode.Error, exception?.Message); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithException_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..2176a495 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,77 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, System.Exception exception) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + + RecordExceptionInternal(activity: activity, exception: exception, escape: true); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + + activity.SetStatus(System.Diagnostics.ActivityStatusCode.Error, "This is a Test"); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnEventAttribute_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..a349af11 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,93 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, string? statusDescription) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: default); + + activity.AddEvent(activityEventEvent); + + activity.SetStatus(System.Diagnostics.ActivityStatusCode.Error, statusDescription); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event2(System.Diagnostics.Activity? activity, string statusDescription_another) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + + System.Diagnostics.ActivityEvent activityEventEvent2 = new System.Diagnostics.ActivityEvent(name: "Event2", timestamp: default, tags: default); + + activity.AddEvent(activityEventEvent2); + + activity.SetStatus(System.Diagnostics.ActivityStatusCode.Error, statusDescription_another); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToErrorWithStatusDescriptionOnParameter_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..08fab4d5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,74 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: default); + + activity.AddEvent(activityEventEvent); + + activity.SetStatus(System.Diagnostics.ActivityStatusCode.Error); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToError_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..4abdb40d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,74 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: default); + + activity.AddEvent(activityEventEvent); + + activity.SetStatus(System.Diagnostics.ActivityStatusCode.Ok); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventStatusCodeParameterSetToOk_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..a03dd61b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,81 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the following values are checked, in order, to use as the status description: on a parameter + /// and the value is not null, an Exception parameter exists, and is not null. The is used. The + /// is used. If none of these values are available, the status description is set to null. + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..8f5c2a50 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,77 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("intparam", intParam); + tagsCollectionEvent.Add("boolparam", boolParam); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + + activity.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..8f5c2a50 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,77 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("intparam", intParam); + tagsCollectionEvent.Add("boolparam", boolParam); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + + activity.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..a03dd61b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,81 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the following values are checked, in order, to use as the status description: on a parameter + /// and the value is not null, an Exception parameter exists, and is not null. The is used. The + /// is used. If none of these values are available, the status description is set to null. + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..6fa876e2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,77 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("intparam", intParam); + tagsCollectionEvent.Add("boolparam", boolParam); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + + activity.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..6fa876e2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,77 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("intparam", intParam); + tagsCollectionEvent.Add("boolparam", boolParam); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + + activity.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesEvent.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..5e13f395 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,88 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("purview.telemetry.sourcegenerator"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity(string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("intparam", intParam); + activityActivity.SetTag("boolparam", boolParam); + } + + if (activityActivity != null) + { + activityActivity.SetBaggage("stringparam", stringParam); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("intparam", intParam); + tagsCollectionEvent.Add("boolparam", boolParam); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + + activity.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenAndNoActivityName_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..ff917350 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,90 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity(string? stringParam, int? intParam, bool? boolParam) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("intparam", intParam); + activityActivity.SetTag("boolparam", boolParam); + } + + if (activityActivity != null) + { + activityActivity.SetBaggage("stringparam", stringParam); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? ActivityWithNullableParams(string? stringParam, int? intParam, bool? boolParam) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivityWithNullableParams = _activitySource.StartActivity(name: "ActivityWithNullableParams", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivityWithNullableParams != null) + { + activityActivityWithNullableParams.SetTag("intparam", intParam); + activityActivityWithNullableParams.SetTag("boolparam", boolParam); + } + + if (activityActivityWithNullableParams != null) + { + activityActivityWithNullableParams.SetBaggage("stringparam", stringParam); + } + + return activityActivityWithNullableParams; + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithNullableParams_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..99b035fa --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,90 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity Activity(string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return null!; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("intparam", intParam); + activityActivity.SetTag("boolparam", boolParam); + } + + if (activityActivity != null) + { + activityActivity.SetBaggage("stringparam", stringParam); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity Event(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return null!; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("intparam", intParam); + tagsCollectionEvent.Add("boolparam", boolParam); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + + activity.SetBaggage("stringparam", stringParam); + } + + return activity; + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningActivity_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..87b76d2b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,90 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity Activity(string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return null!; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("intparam", intParam); + activityActivity.SetTag("boolparam", boolParam); + } + + if (activityActivity != null) + { + activityActivity.SetBaggage("stringparam", stringParam); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? ActivityWithNullableReturnActivity(string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivityWithNullableReturnActivity = _activitySource.StartActivity(name: "ActivityWithNullableReturnActivity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivityWithNullableReturnActivity != null) + { + activityActivityWithNullableReturnActivity.SetTag("intparam", intParam); + activityActivityWithNullableReturnActivity.SetTag("boolparam", boolParam); + } + + if (activityActivityWithNullableReturnActivity != null) + { + activityActivityWithNullableReturnActivity.SetBaggage("stringparam", stringParam); + } + + return activityActivityWithNullableReturnActivity; + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGenWithReturningNullableActivity_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..31ef92b5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,88 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity(string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("intparam", intParam); + activityActivity.SetTag("boolparam", boolParam); + } + + if (activityActivity != null) + { + activityActivity.SetBaggage("stringparam", stringParam); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("intparam", intParam); + tagsCollectionEvent.Add("boolparam", boolParam); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + + activity.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicGen_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..31ef92b5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,88 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity(string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("intparam", intParam); + activityActivity.SetTag("boolparam", boolParam); + } + + if (activityActivity != null) + { + activityActivity.SetBaggage("stringparam", stringParam); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("intparam", intParam); + tagsCollectionEvent.Add("boolparam", boolParam); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + + activity.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCoreDIExtension.DependencyInjection.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCoreDIExtension.DependencyInjection.g.verified.cs new file mode 100644 index 00000000..c132ae74 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCoreDIExtension.DependencyInjection.g.verified.cs @@ -0,0 +1,27 @@ +//HintName: Testing.TestActivitiesCoreDIExtension.DependencyInjection.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Microsoft.Extensions.DependencyInjection +{ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + static class TestActivitiesCoreDIExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static public Microsoft.Extensions.DependencyInjection.IServiceCollection AddTestActivities(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) + { + return services.AddSingleton(); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..31ef92b5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,88 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity(string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("intparam", intParam); + activityActivity.SetTag("boolparam", boolParam); + } + + if (activityActivity != null) + { + activityActivity.SetBaggage("stringparam", stringParam); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("intparam", intParam); + tagsCollectionEvent.Add("boolparam", boolParam); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + + activity.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisableDI_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..31ef92b5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,88 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity(string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("intparam", intParam); + activityActivity.SetTag("boolparam", boolParam); + } + + if (activityActivity != null) + { + activityActivity.SetBaggage("stringparam", stringParam); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("intparam", intParam); + tagsCollectionEvent.Add("boolparam", boolParam); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + + activity.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCoreDIExtension.DependencyInjection.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCoreDIExtension.DependencyInjection.g.verified.cs new file mode 100644 index 00000000..c132ae74 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#Testing.TestActivitiesCoreDIExtension.DependencyInjection.g.verified.cs @@ -0,0 +1,27 @@ +//HintName: Testing.TestActivitiesCoreDIExtension.DependencyInjection.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Microsoft.Extensions.DependencyInjection +{ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + static class TestActivitiesCoreDIExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static public Microsoft.Extensions.DependencyInjection.IServiceCollection AddTestActivities(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) + { + return services.AddSingleton(); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceEnableDI_GeneratesActivity.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..b801b706 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,80 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Context(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + activity.SetTag("intparam", intParam); + activity.SetTag("boolparam", boolParam); + activity.SetBaggage("stringparam", stringParam); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("intparam", intParam); + tagsCollectionEvent.Add("boolparam", boolParam); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + + activity.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0.verified.txt b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0.verified.txt new file mode 100644 index 00000000..5063d95b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet9_0.verified.txt @@ -0,0 +1,38 @@ +{ + Diagnostics: [ + { + Location: /* + +[ActivitySource("testing-activity-source")] +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +public interface ITestActivities { +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + [Context] +^^^^^^^^^^ + void Context(System.Diagnostics.Activity? activity, [Baggage]string stringParam, [Tag]int intParam, bool boolParam); +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + + [Event] +^^^^^^^^ + void Event(System.Diagnostics.Activity? activity, [Baggage]string stringParam, [Tag]int intParam, bool boolParam); +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +} +^ + +*/ + Guid_1: (9,0)-(16,1), + Message: As Event and/ or Context methods are defined, it's best practise to create a specific Activity otherwise the Activity will belong to another operation., + Severity: Info, + WarningLevel: 1, + Descriptor: { + Id: TSG3012, + Title: There are no Activity methods defined, assumed use of Activity.Current, + MessageFormat: As Event and/ or Context methods are defined, it's best practise to create a specific Activity otherwise the Activity will belong to another operation., + Category: Activity.Usage, + DefaultSeverity: Info, + IsEnabledByDefault: true + } + } + ] +} \ No newline at end of file diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..f7be7917 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,93 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("purview.telemetry.sourcegenerator"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity(System.Collections.Generic.List paramName) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("paramname", paramName); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, System.Collections.Generic.List paramName) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("paramname", paramName); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Context(System.Diagnostics.Activity? activity, System.Collections.Generic.List paramName) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + activity.SetTag("paramname", paramName); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..2161a8d2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,93 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("purview.telemetry.sourcegenerator"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity(System.Collections.Generic.IDictionary paramName) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("paramname", paramName); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, System.Collections.Generic.IDictionary paramName) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("paramname", paramName); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Context(System.Diagnostics.Activity? activity, System.Collections.Generic.IDictionary paramName) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + activity.SetTag("paramname", paramName); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..72342450 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,93 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("purview.telemetry.sourcegenerator"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity(System.Collections.Generic.Dictionary paramName) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("paramname", paramName); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, System.Collections.Generic.Dictionary paramName) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("paramname", paramName); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Context(System.Diagnostics.Activity? activity, System.Collections.Generic.Dictionary paramName) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + activity.SetTag("paramname", paramName); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..a346b2be --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,93 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("purview.telemetry.sourcegenerator"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity(System.Collections.Generic.IEnumerable paramName) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("paramname", paramName); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, System.Collections.Generic.IEnumerable paramName) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("paramname", paramName); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Context(System.Diagnostics.Activity? activity, System.Collections.Generic.IEnumerable paramName) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + activity.SetTag("paramname", paramName); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..72342450 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,93 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("purview.telemetry.sourcegenerator"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity(System.Collections.Generic.Dictionary paramName) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("paramname", paramName); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, System.Collections.Generic.Dictionary paramName) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("paramname", paramName); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Context(System.Diagnostics.Activity? activity, System.Collections.Generic.Dictionary paramName) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + activity.SetTag("paramname", paramName); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..2161a8d2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,93 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("purview.telemetry.sourcegenerator"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity(System.Collections.Generic.IDictionary paramName) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("paramname", paramName); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, System.Collections.Generic.IDictionary paramName) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("paramname", paramName); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Context(System.Diagnostics.Activity? activity, System.Collections.Generic.IDictionary paramName) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + activity.SetTag("paramname", paramName); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..a346b2be --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,93 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("purview.telemetry.sourcegenerator"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity(System.Collections.Generic.IEnumerable paramName) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("paramname", paramName); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, System.Collections.Generic.IEnumerable paramName) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("paramname", paramName); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Context(System.Diagnostics.Activity? activity, System.Collections.Generic.IEnumerable paramName) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + activity.SetTag("paramname", paramName); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..f7be7917 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,93 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("purview.telemetry.sourcegenerator"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity(System.Collections.Generic.List paramName) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("paramname", paramName); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, System.Collections.Generic.List paramName) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("paramname", paramName); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Context(System.Diagnostics.Activity? activity, System.Collections.Generic.List paramName) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + activity.SetTag("paramname", paramName); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..ae5a2b1b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,99 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity(string stringNonNullParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetBaggage("stringnonnullparam", stringNonNullParam); + activityActivity.SetBaggage("intparam", intParam.ToString()); + activityActivity.SetBaggage("boolparam", boolParam.ToString()); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, string? stringNullableParam, int? intParam, bool? boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: default); + + activity.AddEvent(activityEventEvent); + + activity.SetBaggage("stringnullableparam", stringNullableParam); + activity.SetBaggage("intparam", intParam?.ToString()); + activity.SetBaggage("boolparam", boolParam?.ToString()); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Context(System.Diagnostics.Activity? activity, System.Object? objectParam, string stringNonNullParam, float? floatParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + activity.SetBaggage("objectparam", objectParam?.ToString()); + activity.SetBaggage("stringnonnullparam", stringNonNullParam); + activity.SetBaggage("floatparam", floatParam?.ToString()); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0.verified.txt b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0.verified.txt new file mode 100644 index 00000000..0e906608 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenWithNonStringBaggage_RaisesDiagnosticAndGenerates.DotNet9_0.verified.txt @@ -0,0 +1,124 @@ +{ + Diagnostics: [ + { + Location: /* + [Activity] + System.Diagnostics.Activity? Activity([Baggage]string stringNonNullParam, [Baggage]int intParam, [Baggage]bool boolParam); + ^^^^^^^^ + +*/ + Guid_1: (12,89)-(12,97), + Message: Baggage parameter types only accept strings, be aware this parameter will have ToString() called., + Severity: Warning, + WarningLevel: 1, + Descriptor: { + Id: TSG3000, + Title: Baggage parameter types only accept strings, + MessageFormat: Baggage parameter types only accept strings, be aware this parameter will have ToString() called., + Category: Activity.Usage, + DefaultSeverity: Warning, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Activity] + System.Diagnostics.Activity? Activity([Baggage]string stringNonNullParam, [Baggage]int intParam, [Baggage]bool boolParam); + ^^^^^^^^^ + +*/ + Guid_1: (12,113)-(12,122), + Message: Baggage parameter types only accept strings, be aware this parameter will have ToString() called., + Severity: Warning, + WarningLevel: 1, + Descriptor: { + Id: TSG3000, + Title: Baggage parameter types only accept strings, + MessageFormat: Baggage parameter types only accept strings, be aware this parameter will have ToString() called., + Category: Activity.Usage, + DefaultSeverity: Warning, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Event] + void Event(System.Diagnostics.Activity? activity, [Baggage]string? stringNullableParam, [Baggage]int? intParam, [Baggage]bool? boolParam); + ^^^^^^^^ + +*/ + Guid_1: (15,103)-(15,111), + Message: Baggage parameter types only accept strings, be aware this parameter will have ToString() called., + Severity: Warning, + WarningLevel: 1, + Descriptor: { + Id: TSG3000, + Title: Baggage parameter types only accept strings, + MessageFormat: Baggage parameter types only accept strings, be aware this parameter will have ToString() called., + Category: Activity.Usage, + DefaultSeverity: Warning, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Event] + void Event(System.Diagnostics.Activity? activity, [Baggage]string? stringNullableParam, [Baggage]int? intParam, [Baggage]bool? boolParam); + ^^^^^^^^^ + +*/ + Guid_1: (15,128)-(15,137), + Message: Baggage parameter types only accept strings, be aware this parameter will have ToString() called., + Severity: Warning, + WarningLevel: 1, + Descriptor: { + Id: TSG3000, + Title: Baggage parameter types only accept strings, + MessageFormat: Baggage parameter types only accept strings, be aware this parameter will have ToString() called., + Category: Activity.Usage, + DefaultSeverity: Warning, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Context] + void Context(System.Diagnostics.Activity? activity, [Baggage]object? objectParam, [Baggage]string stringNonNullParam, [Baggage]float? floatParam); + ^^^^^^^^^^^ +} +*/ + Guid_1: (18,70)-(18,81), + Message: Baggage parameter types only accept strings, be aware this parameter will have ToString() called., + Severity: Warning, + WarningLevel: 1, + Descriptor: { + Id: TSG3000, + Title: Baggage parameter types only accept strings, + MessageFormat: Baggage parameter types only accept strings, be aware this parameter will have ToString() called., + Category: Activity.Usage, + DefaultSeverity: Warning, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Context] + void Context(System.Diagnostics.Activity? activity, [Baggage]object? objectParam, [Baggage]string stringNonNullParam, [Baggage]float? floatParam); + ^^^^^^^^^^ +} +*/ + Guid_1: (18,135)-(18,145), + Message: Baggage parameter types only accept strings, be aware this parameter will have ToString() called., + Severity: Warning, + WarningLevel: 1, + Descriptor: { + Id: TSG3000, + Title: Baggage parameter types only accept strings, + MessageFormat: Baggage parameter types only accept strings, be aware this parameter will have ToString() called., + Category: Activity.Usage, + DefaultSeverity: Warning, + IsEnabledByDefault: true + } + } + ] +} \ No newline at end of file diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..005eb42a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCoreDIExtension.DependencyInjection.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCoreDIExtension.DependencyInjection.g.verified.cs new file mode 100644 index 00000000..bf444614 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCoreDIExtension.DependencyInjection.g.verified.cs @@ -0,0 +1,27 @@ +//HintName: Testing.TestLoggerCoreDIExtension.DependencyInjection.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Microsoft.Extensions.DependencyInjection +{ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + static class TestLoggerCoreDIExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static public Microsoft.Extensions.DependencyInjection.IServiceCollection AddTestLogger(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) + { + return services.AddSingleton(); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenAssemblyEnableDI_GeneratesLog.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..005eb42a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCoreDIExtension.DependencyInjection.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCoreDIExtension.DependencyInjection.g.verified.cs new file mode 100644 index 00000000..bf444614 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCoreDIExtension.DependencyInjection.g.verified.cs @@ -0,0 +1,27 @@ +//HintName: Testing.TestLoggerCoreDIExtension.DependencyInjection.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Microsoft.Extensions.DependencyInjection +{ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + static class TestLoggerCoreDIExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static public Microsoft.Extensions.DependencyInjection.IServiceCollection AddTestLogger(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) + { + return services.AddSingleton(); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesLog.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..005eb42a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesLog.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..005eb42a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCoreDIExtension.DependencyInjection.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCoreDIExtension.DependencyInjection.g.verified.cs new file mode 100644 index 00000000..bf444614 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#Testing.TestLoggerCoreDIExtension.DependencyInjection.g.verified.cs @@ -0,0 +1,27 @@ +//HintName: Testing.TestLoggerCoreDIExtension.DependencyInjection.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Microsoft.Extensions.DependencyInjection +{ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + static class TestLoggerCoreDIExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static public Microsoft.Extensions.DependencyInjection.IServiceCollection AddTestLogger(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) + { + return services.AddSingleton(); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceEnableDI_GeneratesLog.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..9cc03b28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0.verified.txt b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0.verified.txt new file mode 100644 index 00000000..57e758c9 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanOneExceptionParameter_RaisesDiagnostic.DotNet9_0.verified.txt @@ -0,0 +1,23 @@ +{ + Diagnostics: [ + { + Location: /* +public interface ITestLogger { + void Log(string stringParam, Exception exception1, Exception exception2); + ^^^ +} +*/ + Guid_1: (11,6)-(11,9), + Message: Only a single exceptions parameter is permitted., + Severity: Error, + Descriptor: { + Id: TSG2000, + Title: Too many exception parameters, + MessageFormat: Only a single exceptions parameter is permitted., + Category: Logging.Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + } + ] +} \ No newline at end of file diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..9cc03b28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0.verified.txt b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0.verified.txt new file mode 100644 index 00000000..0adb20e2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceMoreThanSixParameters_RaisesDiagnostic.DotNet9_0.verified.txt @@ -0,0 +1,23 @@ +{ + Diagnostics: [ + { + Location: /* +public interface ITestLogger { + void Log(string stringParam, int intParam, bool boolParam, string stringParam1, int intParam1, bool boolParam1, string stringParam2, int intParam2, bool boolParam2); + ^^^ +} +*/ + Guid_1: (11,6)-(11,9), + Message: The maximum number of parameters (excluding optional Exception) is 6, + Severity: Error, + Descriptor: { + Id: TSG2001, + Title: More than 6 parameters, + MessageFormat: The maximum number of parameters (excluding optional Exception) is 6, + Category: Logging.Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + } + ] +} \ No newline at end of file diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..f99c5bbc --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam, System.Exception exception) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, exception); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_217ad9e681c2d140.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..f99c5bbc --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam, System.Exception exception) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, exception); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_3e5e7ecb8eedd10b.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..f99c5bbc --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam, System.Exception exception) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, exception); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_fb648228d4c94bc2.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..f99c5bbc --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam, System.Exception exception) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, exception); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Level = Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..f99c5bbc --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam, System.Exception exception) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, exception); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..f99c5bbc --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam, System.Exception exception) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, exception); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithExplicitLogLevelAndAnExceptionParameter_GenerateLogger_level=level- Microsoft.Extensions.Logging.LogLevel.Trace.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..005eb42a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicExplicitLogEntry_GenerateLogger.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..005eb42a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSingleBasicImplicitLogEntry_GenerateLogger.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..a43c02b3 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Critical, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Critical)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_0ce3af4fbf68c2cc.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..dcc1c7d5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Error, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_778fa5ff7ffc7e1e.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..71e1b75f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Debug, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_79f4326d30e2b4ee.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..005eb42a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_8d681205b5eef3c7.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..a43c02b3 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Critical, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Critical)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Critical.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..71e1b75f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Debug, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Debug.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..dcc1c7d5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Error, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Error.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..005eb42a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Info.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..eb517fe6 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Trace.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..5046d0bb --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Warning, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_attribute=Warning.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..eb517fe6 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_dc4676b742d32645.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..5046d0bb --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Warning, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel_e6994dc199d46f6f.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..22b3ad93 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,106 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Critical, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Critical, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_1"), "Test.Log_EventId_1: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Critical, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_3"), "Test.Log_EventId_3: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_MessageTemplate_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Critical, default, "template"); + static readonly System.Action _log_MessageTemplate_2Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Critical, default, "template"); + static readonly System.Action _log_MessageTemplate_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Critical, default, "template"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Critical)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Critical)) + { + return; + } + + _log_EventId_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Critical)) + { + return; + } + + _log_EventId_3Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Critical)) + { + return; + } + + _log_MessageTemplate_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_2(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Critical)) + { + return; + } + + _log_MessageTemplate_2Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Critical)) + { + return; + } + + _log_MessageTemplate_3Action(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_0ce3af4fbf68c2cc.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..725676f9 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,106 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Error, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Error, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_1"), "Test.Log_EventId_1: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Error, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_3"), "Test.Log_EventId_3: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_MessageTemplate_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Error, default, "template"); + static readonly System.Action _log_MessageTemplate_2Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Error, default, "template"); + static readonly System.Action _log_MessageTemplate_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Error, default, "template"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) + { + return; + } + + _log_EventId_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) + { + return; + } + + _log_EventId_3Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) + { + return; + } + + _log_MessageTemplate_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_2(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) + { + return; + } + + _log_MessageTemplate_2Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) + { + return; + } + + _log_MessageTemplate_3Action(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_778fa5ff7ffc7e1e.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..15e3084e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,106 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Debug, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Debug, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_1"), "Test.Log_EventId_1: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Debug, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_3"), "Test.Log_EventId_3: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_MessageTemplate_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Debug, default, "template"); + static readonly System.Action _log_MessageTemplate_2Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Debug, default, "template"); + static readonly System.Action _log_MessageTemplate_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Debug, default, "template"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) + { + return; + } + + _log_EventId_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) + { + return; + } + + _log_EventId_3Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) + { + return; + } + + _log_MessageTemplate_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_2(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) + { + return; + } + + _log_MessageTemplate_2Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) + { + return; + } + + _log_MessageTemplate_3Action(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_79f4326d30e2b4ee.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..b6ceece9 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,106 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_1"), "Test.Log_EventId_1: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_3"), "Test.Log_EventId_3: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_MessageTemplate_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "template"); + static readonly System.Action _log_MessageTemplate_2Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "template"); + static readonly System.Action _log_MessageTemplate_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "template"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _log_EventId_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _log_EventId_3Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _log_MessageTemplate_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_2(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _log_MessageTemplate_2Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _log_MessageTemplate_3Action(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_8d681205b5eef3c7.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..22b3ad93 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,106 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Critical, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Critical, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_1"), "Test.Log_EventId_1: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Critical, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_3"), "Test.Log_EventId_3: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_MessageTemplate_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Critical, default, "template"); + static readonly System.Action _log_MessageTemplate_2Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Critical, default, "template"); + static readonly System.Action _log_MessageTemplate_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Critical, default, "template"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Critical)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Critical)) + { + return; + } + + _log_EventId_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Critical)) + { + return; + } + + _log_EventId_3Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Critical)) + { + return; + } + + _log_MessageTemplate_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_2(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Critical)) + { + return; + } + + _log_MessageTemplate_2Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Critical)) + { + return; + } + + _log_MessageTemplate_3Action(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Critical.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..15e3084e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,106 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Debug, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Debug, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_1"), "Test.Log_EventId_1: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Debug, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_3"), "Test.Log_EventId_3: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_MessageTemplate_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Debug, default, "template"); + static readonly System.Action _log_MessageTemplate_2Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Debug, default, "template"); + static readonly System.Action _log_MessageTemplate_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Debug, default, "template"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) + { + return; + } + + _log_EventId_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) + { + return; + } + + _log_EventId_3Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) + { + return; + } + + _log_MessageTemplate_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_2(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) + { + return; + } + + _log_MessageTemplate_2Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) + { + return; + } + + _log_MessageTemplate_3Action(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Debug.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..725676f9 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,106 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Error, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Error, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_1"), "Test.Log_EventId_1: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Error, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_3"), "Test.Log_EventId_3: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_MessageTemplate_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Error, default, "template"); + static readonly System.Action _log_MessageTemplate_2Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Error, default, "template"); + static readonly System.Action _log_MessageTemplate_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Error, default, "template"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) + { + return; + } + + _log_EventId_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) + { + return; + } + + _log_EventId_3Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) + { + return; + } + + _log_MessageTemplate_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_2(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) + { + return; + } + + _log_MessageTemplate_2Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) + { + return; + } + + _log_MessageTemplate_3Action(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Error.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..b6ceece9 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,106 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_1"), "Test.Log_EventId_1: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_3"), "Test.Log_EventId_3: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_MessageTemplate_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "template"); + static readonly System.Action _log_MessageTemplate_2Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "template"); + static readonly System.Action _log_MessageTemplate_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "template"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _log_EventId_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _log_EventId_3Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _log_MessageTemplate_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_2(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _log_MessageTemplate_2Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _log_MessageTemplate_3Action(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Info.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..65b1b8e6 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,106 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_1"), "Test.Log_EventId_1: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_3"), "Test.Log_EventId_3: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_MessageTemplate_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, default, "template"); + static readonly System.Action _log_MessageTemplate_2Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, default, "template"); + static readonly System.Action _log_MessageTemplate_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, default, "template"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _log_EventId_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _log_EventId_3Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _log_MessageTemplate_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_2(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _log_MessageTemplate_2Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _log_MessageTemplate_3Action(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Trace.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..392165d5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,106 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Warning, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Warning, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_1"), "Test.Log_EventId_1: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Warning, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_3"), "Test.Log_EventId_3: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_MessageTemplate_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Warning, default, "template"); + static readonly System.Action _log_MessageTemplate_2Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Warning, default, "template"); + static readonly System.Action _log_MessageTemplate_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Warning, default, "template"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) + { + return; + } + + _log_EventId_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) + { + return; + } + + _log_EventId_3Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) + { + return; + } + + _log_MessageTemplate_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_2(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) + { + return; + } + + _log_MessageTemplate_2Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) + { + return; + } + + _log_MessageTemplate_3Action(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_attribute=Warning.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..65b1b8e6 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,106 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_1"), "Test.Log_EventId_1: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_3"), "Test.Log_EventId_3: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_MessageTemplate_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, default, "template"); + static readonly System.Action _log_MessageTemplate_2Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, default, "template"); + static readonly System.Action _log_MessageTemplate_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, default, "template"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _log_EventId_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _log_EventId_3Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _log_MessageTemplate_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_2(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _log_MessageTemplate_2Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _log_MessageTemplate_3Action(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_dc4676b742d32645.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..392165d5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,106 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Warning, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Warning, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_1"), "Test.Log_EventId_1: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_EventId_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Warning, new Microsoft.Extensions.Logging.EventId(100, "Test.Log_EventId_3"), "Test.Log_EventId_3: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Action _log_MessageTemplate_1Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Warning, default, "template"); + static readonly System.Action _log_MessageTemplate_2Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Warning, default, "template"); + static readonly System.Action _log_MessageTemplate_3Action = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Warning, default, "template"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) + { + return; + } + + _log_EventId_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_EventId_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) + { + return; + } + + _log_EventId_3Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_1(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) + { + return; + } + + _log_MessageTemplate_1Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_2(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) + { + return; + } + + _log_MessageTemplate_2Action(_logger, stringParam, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log_MessageTemplate_3(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning)) + { + return; + } + + _log_MessageTemplate_3Action(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter_e6994dc199d46f6f.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..1dd35e0b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Error, default, "Test.Log: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam, System.Exception exception) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, exception); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0.verified.txt b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0.verified.txt new file mode 100644 index 00000000..40ee1f5b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenInterfaceWithoutExplicitLogLevelAndAnExceptionParameter_GenerateLogger.DotNet9_0.verified.txt @@ -0,0 +1,24 @@ +{ + Diagnostics: [ + { + Location: /* +public interface ITestLogger { + void Log(string stringParam, int intParam, bool boolParam, Exception exception); + ^^^ +} +*/ + Guid_1: (11,6)-(11,9), + Message: Because an exception parameter was defined and no log level was defined the level was inferred to be Error. Consider explicitly defining the required level., + Severity: Info, + WarningLevel: 1, + Descriptor: { + Id: TSG2002, + Title: Inferring error log level, + MessageFormat: Because an exception parameter was defined and no log level was defined the level was inferred to be Error. Consider explicitly defining the required level., + Category: Logging.Usage, + DefaultSeverity: Info, + IsEnabledByDefault: true + } + } + ] +} \ No newline at end of file diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..59ea50d1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.custom-log-entry-name: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_1b29483bff66a5ab.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..76627169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.LogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_8d01237e67abd299.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..9f1b925b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.123: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_a6fe7c9427ed8466.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..8b0022e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.CustomLogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_db75e297eab70065.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..9f1b925b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.123: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=123.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..8b0022e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.CustomLogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..76627169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.LogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..59ea50d1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.custom-log-entry-name: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithEntryName_GenerateLogger_logTargetName=custom-log-entry-name.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..9f1b925b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.123: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23a24e5d4d2b1fa4.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..5cefe8a0 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "123: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_23d331d63de79f56.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..1cfcc0d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "custom-prefix.123: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_25b5d63d1863b1e8.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..5e5e0925 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "ITestLogger.123: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ff0ef173511216.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..76627169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.LogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_27ffc49cefc1097a.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..3e605f76 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "ITestLogger.CustomLogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_40a62bef99b74cc8.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..0cefd6d1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "custom-prefix.custom-log-entry-name: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_443c49538657a3c5.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..39d96d68 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "TestLoggerCore.123: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_45360a436645308f.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..cd40b1ef --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "custom-prefix.LogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_4f78ca5829c0ac8b.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..0bdc6e4b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "TestLoggerCore.CustomLogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_56ec91b75e072875.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..59ea50d1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.custom-log-entry-name: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_573cd7c6e681a547.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..845ef283 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "LogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_57c7e6f72cba80de.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..0575653d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "ITestLogger.LogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_6b49a5c889d3673d.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..0da9e83b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "custom-prefix.CustomLogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_7737ad91a91544e1.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..234173b5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "TestLoggerCore.custom-log-entry-name: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_79c09446e81a9f39.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..92af6ef7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "TestLoggerCore.LogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_81fa10ba104eab79.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..b52c129b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "CustomLogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_86657b757e360ffd.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..8b0022e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.CustomLogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_a782ba27c266730f.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..7eb6d8c4 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "custom-log-entry-name: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e59950753793d988.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..fce60321 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "ITestLogger.custom-log-entry-name: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_e6260230e49c8e61.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..39d96d68 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "TestLoggerCore.123: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=123.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..0bdc6e4b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "TestLoggerCore.CustomLogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..92af6ef7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "TestLoggerCore.LogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..234173b5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "TestLoggerCore.custom-log-entry-name: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Class_logTargetName=custom-log-entry-name.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..1cfcc0d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "custom-prefix.123: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=123.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..0da9e83b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "custom-prefix.CustomLogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..cd40b1ef --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "custom-prefix.LogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..0cefd6d1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "custom-prefix.custom-log-entry-name: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Custom, CustomPrefix = -custom-prefix-_logTargetName=custom-log-entry-name.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..9f1b925b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.123: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=123.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..8b0022e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.CustomLogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..76627169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.LogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..59ea50d1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.custom-log-entry-name: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Default_logTargetName=custom-log-entry-name.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..5e5e0925 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "ITestLogger.123: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=123.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..3e605f76 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "ITestLogger.CustomLogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..0575653d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "ITestLogger.LogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..fce60321 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "ITestLogger.custom-log-entry-name: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=Interface_logTargetName=custom-log-entry-name.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..5cefe8a0 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "123: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=123.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..b52c129b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "CustomLogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=CustomLogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..845ef283 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "LogNameSetViaLogTargetAttribute: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=LogNameSetViaLogTargetAttribute.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..7eb6d8c4 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "custom-log-entry-name: stringParam: {StringParam}, intParam: {IntParam}, boolParam: {BoolParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(string stringParam, int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, stringParam, intParam, boolParam, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLogTargetWithPrefixAndEntryName_GenerateLogger_type=NoSuffix_logTargetName=custom-log-entry-name.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#Testing.Test1.Test2.TestClass1.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#Testing.Test1.Test2.TestClass1.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..87738d8c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#Testing.Test1.Test2.TestClass1.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,39 @@ +//HintName: Testing.Test1.Test2.TestClass1.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing.Test1.Test2 +{ + partial class TestClass1 + { + sealed partial class TestLoggerCore : Testing.Test1.Test2.TestClass1.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#Testing.Test1.TestClass1.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#Testing.Test1.TestClass1.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..ef85e3bb --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#Testing.Test1.TestClass1.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,39 @@ +//HintName: Testing.Test1.TestClass1.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing.Test1 +{ + partial class TestClass1 + { + sealed partial class TestLoggerCore : Testing.Test1.TestClass1.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#Testing.Test1.Test2.Test3.TestClass1.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#Testing.Test1.Test2.Test3.TestClass1.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..a5f8ab69 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#Testing.Test1.Test2.Test3.TestClass1.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,39 @@ +//HintName: Testing.Test1.Test2.Test3.TestClass1.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing.Test1.Test2.Test3 +{ + partial class TestClass1 + { + sealed partial class TestLoggerCore : Testing.Test1.Test2.Test3.TestClass1.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#Testing.Test1.TestClass1.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#Testing.Test1.TestClass1.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..ef85e3bb --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#Testing.Test1.TestClass1.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,39 @@ +//HintName: Testing.Test1.TestClass1.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing.Test1 +{ + partial class TestClass1 + { + sealed partial class TestLoggerCore : Testing.Test1.TestClass1.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#Testing.Test1.Test2.TestClass1.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#Testing.Test1.Test2.TestClass1.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..87738d8c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#Testing.Test1.Test2.TestClass1.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,39 @@ +//HintName: Testing.Test1.Test2.TestClass1.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing.Test1.Test2 +{ + partial class TestClass1 + { + sealed partial class TestLoggerCore : Testing.Test1.Test2.TestClass1.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#Testing.Test1.Test2.Test3.TestClass1.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#Testing.Test1.Test2.Test3.TestClass1.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..a5f8ab69 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#Testing.Test1.Test2.Test3.TestClass1.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,39 @@ +//HintName: Testing.Test1.Test2.Test3.TestClass1.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing.Test1.Test2.Test3 +{ + partial class TestClass1 + { + sealed partial class TestLoggerCore : Testing.Test1.Test2.Test3.TestClass1.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClass_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#Testing.Test1.Test2.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#Testing.Test1.Test2.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..e3fb46ab --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#Testing.Test1.Test2.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,45 @@ +//HintName: Testing.Test1.Test2.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing.Test1.Test2 +{ + partial class TestClass1 + { + partial class TestClass2 + { + partial class TestClass3 + { + sealed partial class TestLoggerCore : Testing.Test1.Test2.TestClass1.TestClass2.TestClass3.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } + } + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#Testing.Test1.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#Testing.Test1.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..41a34a03 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#Testing.Test1.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,45 @@ +//HintName: Testing.Test1.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing.Test1 +{ + partial class TestClass1 + { + partial class TestClass2 + { + partial class TestClass3 + { + sealed partial class TestLoggerCore : Testing.Test1.TestClass1.TestClass2.TestClass3.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } + } + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#Testing.Test1.Test2.Test3.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#Testing.Test1.Test2.Test3.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..38139a53 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#Testing.Test1.Test2.Test3.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,45 @@ +//HintName: Testing.Test1.Test2.Test3.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing.Test1.Test2.Test3 +{ + partial class TestClass1 + { + partial class TestClass2 + { + partial class TestClass3 + { + sealed partial class TestLoggerCore : Testing.Test1.Test2.Test3.TestClass1.TestClass2.TestClass3.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } + } + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#Testing.Test1.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#Testing.Test1.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..41a34a03 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#Testing.Test1.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,45 @@ +//HintName: Testing.Test1.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing.Test1 +{ + partial class TestClass1 + { + partial class TestClass2 + { + partial class TestClass3 + { + sealed partial class TestLoggerCore : Testing.Test1.TestClass1.TestClass2.TestClass3.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } + } + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#Testing.Test1.Test2.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#Testing.Test1.Test2.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..e3fb46ab --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#Testing.Test1.Test2.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,45 @@ +//HintName: Testing.Test1.Test2.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing.Test1.Test2 +{ + partial class TestClass1 + { + partial class TestClass2 + { + partial class TestClass3 + { + sealed partial class TestLoggerCore : Testing.Test1.Test2.TestClass1.TestClass2.TestClass3.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } + } + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#Testing.Test1.Test2.Test3.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#Testing.Test1.Test2.Test3.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..38139a53 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#Testing.Test1.Test2.Test3.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,45 @@ +//HintName: Testing.Test1.Test2.Test3.TestClass1.TestClass2.TestClass3.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing.Test1.Test2.Test3 +{ + partial class TestClass1 + { + partial class TestClass2 + { + partial class TestClass3 + { + sealed partial class TestLoggerCore : Testing.Test1.Test2.Test3.TestClass1.TestClass2.TestClass3.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } + } + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespacesAndNestedClasses_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#Testing.Test1.Test2.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#Testing.Test1.Test2.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..4317fbc5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#Testing.Test1.Test2.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,36 @@ +//HintName: Testing.Test1.Test2.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing.Test1.Test2 +{ + sealed partial class TestLoggerCore : Testing.Test1.Test2.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_722fedf52fa6407d.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#Testing.Test1.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#Testing.Test1.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..a45fc866 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#Testing.Test1.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,36 @@ +//HintName: Testing.Test1.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing.Test1 +{ + sealed partial class TestLoggerCore : Testing.Test1.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_739dd5ba31468031.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#Testing.Test1.Test2.Test3.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#Testing.Test1.Test2.Test3.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..acff74f8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#Testing.Test1.Test2.Test3.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,36 @@ +//HintName: Testing.Test1.Test2.Test3.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing.Test1.Test2.Test3 +{ + sealed partial class TestLoggerCore : Testing.Test1.Test2.Test3.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_ef161dc9a739b096.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#Testing.Test1.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#Testing.Test1.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..a45fc866 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#Testing.Test1.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,36 @@ +//HintName: Testing.Test1.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing.Test1 +{ + sealed partial class TestLoggerCore : Testing.Test1.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#Testing.Test1.Test2.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#Testing.Test1.Test2.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..4317fbc5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#Testing.Test1.Test2.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,36 @@ +//HintName: Testing.Test1.Test2.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing.Test1.Test2 +{ + sealed partial class TestLoggerCore : Testing.Test1.Test2.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#Testing.Test1.Test2.Test3.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#Testing.Test1.Test2.Test3.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..acff74f8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#Testing.Test1.Test2.Test3.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,36 @@ +//HintName: Testing.Test1.Test2.Test3.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing.Test1.Test2.Test3 +{ + sealed partial class TestLoggerCore : Testing.Test1.Test2.Test3.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenLoggerWithNamespaces_GeneratesScopedLogTarget_namespace=Testing.Test1.Test2.Test3.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..beac93ed --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,36 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log() + { + return _logAction(_logger); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..5e122157 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action, System.Exception?> _logEntryWithGenericTypeParamAction = Microsoft.Extensions.Logging.LoggerMessage.Define>(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.LogEntryWithGenericTypeParam: paramName: {ParamName}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void LogEntryWithGenericTypeParam(System.Collections.Generic.List paramName) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logEntryWithGenericTypeParamAction(_logger, paramName, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..27991d8a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action, System.Exception?> _logEntryWithGenericTypeParamAction = Microsoft.Extensions.Logging.LoggerMessage.Define>(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.LogEntryWithGenericTypeParam: paramName: {ParamName}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void LogEntryWithGenericTypeParam(System.Collections.Generic.IDictionary paramName) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logEntryWithGenericTypeParamAction(_logger, paramName, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..3d0ab43e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action, System.Exception?> _logEntryWithGenericTypeParamAction = Microsoft.Extensions.Logging.LoggerMessage.Define>(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.LogEntryWithGenericTypeParam: paramName: {ParamName}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void LogEntryWithGenericTypeParam(System.Collections.Generic.Dictionary paramName) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logEntryWithGenericTypeParamAction(_logger, paramName, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..b7e7bd32 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action, System.Exception?> _logEntryWithGenericTypeParamAction = Microsoft.Extensions.Logging.LoggerMessage.Define>(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.LogEntryWithGenericTypeParam: paramName: {ParamName}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void LogEntryWithGenericTypeParam(System.Collections.Generic.IEnumerable paramName) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logEntryWithGenericTypeParamAction(_logger, paramName, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..3d0ab43e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action, System.Exception?> _logEntryWithGenericTypeParamAction = Microsoft.Extensions.Logging.LoggerMessage.Define>(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.LogEntryWithGenericTypeParam: paramName: {ParamName}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void LogEntryWithGenericTypeParam(System.Collections.Generic.Dictionary paramName) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logEntryWithGenericTypeParamAction(_logger, paramName, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..27991d8a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action, System.Exception?> _logEntryWithGenericTypeParamAction = Microsoft.Extensions.Logging.LoggerMessage.Define>(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.LogEntryWithGenericTypeParam: paramName: {ParamName}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void LogEntryWithGenericTypeParam(System.Collections.Generic.IDictionary paramName) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logEntryWithGenericTypeParamAction(_logger, paramName, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..b7e7bd32 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action, System.Exception?> _logEntryWithGenericTypeParamAction = Microsoft.Extensions.Logging.LoggerMessage.Define>(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.LogEntryWithGenericTypeParam: paramName: {ParamName}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void LogEntryWithGenericTypeParam(System.Collections.Generic.IEnumerable paramName) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logEntryWithGenericTypeParamAction(_logger, paramName, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..5e122157 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action, System.Exception?> _logEntryWithGenericTypeParamAction = Microsoft.Extensions.Logging.LoggerMessage.Define>(Microsoft.Extensions.Logging.LogLevel.Information, default, "Test.LogEntryWithGenericTypeParam: paramName: {ParamName}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void LogEntryWithGenericTypeParam(System.Collections.Generic.List paramName) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logEntryWithGenericTypeParamAction(_logger, paramName, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..828924a2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,36 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}, exception: {Exception}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam, System.Exception exception) + { + return _logAction(_logger, stringParam, intParam, exception); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsAndExceptionReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs new file mode 100644 index 00000000..5ff40a81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#Testing.TestLoggerCore.Logging.g.verified.cs @@ -0,0 +1,36 @@ +//HintName: Testing.TestLoggerCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestLoggerCore : Testing.ITestLogger + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _logAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("Test.Log: stringParam: {StringParam}, intParam: {IntParam}"); + + public TestLoggerCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? Log(string stringParam, int intParam) + { + return _logAction(_logger, stringParam, intParam); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorLoggingTests.Generate_GivenMethodWithParamsReturnsIDisposable_GeneratesScopedLogEntry.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..e30e13a5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,109 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _counterInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary counterTags = new System.Collections.Generic.Dictionary(); + + PopulateCounterTags(counterTags); + +#endif + + _counterInstrument = _meter.CreateCounter(name: "counter", unit: null, description: null +#if !NET7_0 + , tags: counterTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter(int counterValue, int intParam, bool boolParam) + { + if (_counterInstrument == null) + { + return; + } + + System.Diagnostics.TagList counterTagList = new System.Diagnostics.TagList(); + + counterTagList.Add("intparam", intParam); + counterTagList.Add("boolparam", boolParam); + + _counterInstrument.Add(counterValue, tagList: counterTagList); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCoreDIExtension.DependencyInjection.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCoreDIExtension.DependencyInjection.g.verified.cs new file mode 100644 index 00000000..eb07be04 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCoreDIExtension.DependencyInjection.g.verified.cs @@ -0,0 +1,27 @@ +//HintName: Testing.TestMetricsCoreDIExtension.DependencyInjection.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Microsoft.Extensions.DependencyInjection +{ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + static class TestMetricsCoreDIExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static public Microsoft.Extensions.DependencyInjection.IServiceCollection AddTestMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) + { + return services.AddSingleton(); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAssemblyEnableDI_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..a09ca933 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0.verified.txt b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0.verified.txt new file mode 100644 index 00000000..9bceddd4 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenAutoCounterWithInstrumentationValue_GeneratesDiagnostic.DotNet9_0.verified.txt @@ -0,0 +1,23 @@ +{ + Diagnostics: [ + { + Location: /* + [AutoCounter] + void AutoCounter([InstrumentMeasurement]int value, [Tag]int intParam, [Tag]bool boolParam); + ^^^^^^^^^^^ +} +*/ + Guid_1: (13,6)-(13,17), + Message: Auto increment counter and a measurement parameter are defined, either remove the parameter or disable auto increment., + Severity: Error, + Descriptor: { + Id: TSG4002, + Title: Auto increment counter and measurement defined, + MessageFormat: Auto increment counter and a measurement parameter are defined, either remove the parameter or disable auto increment., + Category: Metrics.Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + } + ] +} \ No newline at end of file diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..cc9fc5d2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,108 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _autoCounterInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoCounterTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoCounterTags(autoCounterTags); + +#endif + + _autoCounterInstrument = _meter.CreateCounter(name: "autocounter", unit: null, description: null +#if !NET7_0 + , tags: autoCounterTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoCounter(int intParam) + { + if (_autoCounterInstrument == null) + { + return; + } + + System.Diagnostics.TagList autoCounterTagList = new System.Diagnostics.TagList(); + + autoCounterTagList.Add("intparam", intParam); + + _autoCounterInstrument.Add(1, tagList: autoCounterTagList); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithInferredTagsOfInstrumentType_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..a09ca933 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0.verified.txt b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0.verified.txt new file mode 100644 index 00000000..88ae43dc --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounterWithSpecifiedInstrumentMeasurement_GeneratesDiagnostic.DotNet9_0.verified.txt @@ -0,0 +1,23 @@ +{ + Diagnostics: [ + { + Location: /* + [AutoCounter] + void AutoCounter([InstrumentMeasurement]int intParam); + ^^^^^^^^^^^ +} +*/ + Guid_1: (13,6)-(13,17), + Message: Auto increment counter and a measurement parameter are defined, either remove the parameter or disable auto increment., + Severity: Error, + Descriptor: { + Id: TSG4002, + Title: Auto increment counter and measurement defined, + MessageFormat: Auto increment counter and a measurement parameter are defined, either remove the parameter or disable auto increment., + Category: Metrics.Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + } + ] +} \ No newline at end of file diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..a0381a3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,109 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _autoCounterInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoCounterTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoCounterTags(autoCounterTags); + +#endif + + _autoCounterInstrument = _meter.CreateCounter(name: "autocounter", unit: null, description: null +#if !NET7_0 + , tags: autoCounterTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoCounter(int intParam, bool boolParam) + { + if (_autoCounterInstrument == null) + { + return; + } + + System.Diagnostics.TagList autoCounterTagList = new System.Diagnostics.TagList(); + + autoCounterTagList.Add("intparam", intParam); + autoCounterTagList.Add("boolparam", boolParam); + + _autoCounterInstrument.Add(1, tagList: autoCounterTagList); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicAutoCounter_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..56f89757 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,175 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _counter1Instrument = null; + System.Diagnostics.Metrics.Counter? _counter2Instrument = null; + System.Diagnostics.Metrics.Counter? _counter3Instrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary counter1Tags = new System.Collections.Generic.Dictionary(); + + PopulateCounter1Tags(counter1Tags); + +#endif + + _counter1Instrument = _meter.CreateCounter(name: "counter1", unit: null, description: null +#if !NET7_0 + , tags: counter1Tags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counter2Tags = new System.Collections.Generic.Dictionary(); + + PopulateCounter2Tags(counter2Tags); + +#endif + + _counter2Instrument = _meter.CreateCounter(name: "counter2", unit: null, description: null +#if !NET7_0 + , tags: counter2Tags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counter3Tags = new System.Collections.Generic.Dictionary(); + + PopulateCounter3Tags(counter3Tags); + +#endif + + _counter3Instrument = _meter.CreateCounter(name: "counter3", unit: null, description: null +#if !NET7_0 + , tags: counter3Tags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateCounter1Tags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounter2Tags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounter3Tags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter1(int intParam, bool boolParam) + { + if (_counter1Instrument == null) + { + return; + } + + System.Diagnostics.TagList counter1TagList = new System.Diagnostics.TagList(); + + counter1TagList.Add("intparam", intParam); + counter1TagList.Add("boolparam", boolParam); + + _counter1Instrument.Add(1, tagList: counter1TagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter2(int intParam, bool boolParam) + { + if (_counter2Instrument == null) + { + return; + } + + System.Diagnostics.TagList counter2TagList = new System.Diagnostics.TagList(); + + counter2TagList.Add("intparam", intParam); + counter2TagList.Add("boolparam", boolParam); + + _counter2Instrument.Add(1, tagList: counter2TagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter3(int intParam, bool boolParam) + { + if (_counter3Instrument == null) + { + return; + } + + System.Diagnostics.TagList counter3TagList = new System.Diagnostics.TagList(); + + counter3TagList.Add("intparam", intParam); + counter3TagList.Add("boolparam", boolParam); + + _counter3Instrument.Add(1, tagList: counter3TagList); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCountersWithAutoIncrement_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..891af867 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,307 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _counterInstrument = null; + System.Diagnostics.Metrics.Counter? _counter2Instrument = null; + System.Diagnostics.Metrics.Counter? _counter3Instrument = null; + System.Diagnostics.Metrics.Counter? _counter4Instrument = null; + System.Diagnostics.Metrics.Counter? _counter5Instrument = null; + System.Diagnostics.Metrics.Counter? _counter6Instrument = null; + System.Diagnostics.Metrics.Counter? _counter7Instrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary counterTags = new System.Collections.Generic.Dictionary(); + + PopulateCounterTags(counterTags); + +#endif + + _counterInstrument = _meter.CreateCounter(name: "counter", unit: null, description: null +#if !NET7_0 + , tags: counterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counter2Tags = new System.Collections.Generic.Dictionary(); + + PopulateCounter2Tags(counter2Tags); + +#endif + + _counter2Instrument = _meter.CreateCounter(name: "counter2", unit: null, description: null +#if !NET7_0 + , tags: counter2Tags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counter3Tags = new System.Collections.Generic.Dictionary(); + + PopulateCounter3Tags(counter3Tags); + +#endif + + _counter3Instrument = _meter.CreateCounter(name: "counter3", unit: null, description: null +#if !NET7_0 + , tags: counter3Tags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counter4Tags = new System.Collections.Generic.Dictionary(); + + PopulateCounter4Tags(counter4Tags); + +#endif + + _counter4Instrument = _meter.CreateCounter(name: "counter4", unit: null, description: null +#if !NET7_0 + , tags: counter4Tags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counter5Tags = new System.Collections.Generic.Dictionary(); + + PopulateCounter5Tags(counter5Tags); + +#endif + + _counter5Instrument = _meter.CreateCounter(name: "counter5", unit: null, description: null +#if !NET7_0 + , tags: counter5Tags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counter6Tags = new System.Collections.Generic.Dictionary(); + + PopulateCounter6Tags(counter6Tags); + +#endif + + _counter6Instrument = _meter.CreateCounter(name: "counter6", unit: null, description: null +#if !NET7_0 + , tags: counter6Tags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counter7Tags = new System.Collections.Generic.Dictionary(); + + PopulateCounter7Tags(counter7Tags); + +#endif + + _counter7Instrument = _meter.CreateCounter(name: "counter7", unit: null, description: null +#if !NET7_0 + , tags: counter7Tags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateCounterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounter2Tags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounter3Tags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounter4Tags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounter5Tags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounter6Tags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounter7Tags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter(int counterValue, int intParam, bool boolParam) + { + if (_counterInstrument == null) + { + return; + } + + System.Diagnostics.TagList counterTagList = new System.Diagnostics.TagList(); + + counterTagList.Add("intparam", intParam); + counterTagList.Add("boolparam", boolParam); + + _counterInstrument.Add(counterValue, tagList: counterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter2(byte counterValue, int intParam, bool boolParam) + { + if (_counter2Instrument == null) + { + return; + } + + System.Diagnostics.TagList counter2TagList = new System.Diagnostics.TagList(); + + counter2TagList.Add("intparam", intParam); + counter2TagList.Add("boolparam", boolParam); + + _counter2Instrument.Add(counterValue, tagList: counter2TagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter3(long counterValue, int intParam, bool boolParam) + { + if (_counter3Instrument == null) + { + return; + } + + System.Diagnostics.TagList counter3TagList = new System.Diagnostics.TagList(); + + counter3TagList.Add("intparam", intParam); + counter3TagList.Add("boolparam", boolParam); + + _counter3Instrument.Add(counterValue, tagList: counter3TagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter4(short counterValue, int intParam, bool boolParam) + { + if (_counter4Instrument == null) + { + return; + } + + System.Diagnostics.TagList counter4TagList = new System.Diagnostics.TagList(); + + counter4TagList.Add("intparam", intParam); + counter4TagList.Add("boolparam", boolParam); + + _counter4Instrument.Add(counterValue, tagList: counter4TagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter5(double counterValue, int intParam, bool boolParam) + { + if (_counter5Instrument == null) + { + return; + } + + System.Diagnostics.TagList counter5TagList = new System.Diagnostics.TagList(); + + counter5TagList.Add("intparam", intParam); + counter5TagList.Add("boolparam", boolParam); + + _counter5Instrument.Add(counterValue, tagList: counter5TagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter6(float counterValue, int intParam, bool boolParam) + { + if (_counter6Instrument == null) + { + return; + } + + System.Diagnostics.TagList counter6TagList = new System.Diagnostics.TagList(); + + counter6TagList.Add("intparam", intParam); + counter6TagList.Add("boolparam", boolParam); + + _counter6Instrument.Add(counterValue, tagList: counter6TagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter7(decimal counterValue, int intParam, bool boolParam) + { + if (_counter7Instrument == null) + { + return; + } + + System.Diagnostics.TagList counter7TagList = new System.Diagnostics.TagList(); + + counter7TagList.Add("intparam", intParam); + counter7TagList.Add("boolparam", boolParam); + + _counter7Instrument.Add(counterValue, tagList: counter7TagList); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicCounters_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..2615f87d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,142 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Histogram? _histogramInstrument = null; + System.Diagnostics.Metrics.Histogram? _histogram1Instrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary histogramTags = new System.Collections.Generic.Dictionary(); + + PopulateHistogramTags(histogramTags); + +#endif + + _histogramInstrument = _meter.CreateHistogram(name: "histogram", unit: null, description: null +#if !NET7_0 + , tags: histogramTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary histogram1Tags = new System.Collections.Generic.Dictionary(); + + PopulateHistogram1Tags(histogram1Tags); + +#endif + + _histogram1Instrument = _meter.CreateHistogram(name: "histogram1", unit: null, description: null +#if !NET7_0 + , tags: histogram1Tags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateHistogramTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateHistogram1Tags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Histogram(int counterValue, int intParam, bool boolParam) + { + if (_histogramInstrument == null) + { + return; + } + + System.Diagnostics.TagList histogramTagList = new System.Diagnostics.TagList(); + + histogramTagList.Add("intparam", intParam); + histogramTagList.Add("boolparam", boolParam); + + _histogramInstrument.Record(counterValue, tagList: histogramTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Histogram1(int counterValue, int intParam, bool boolParam) + { + if (_histogram1Instrument == null) + { + return; + } + + System.Diagnostics.TagList histogram1TagList = new System.Diagnostics.TagList(); + + histogram1TagList.Add("intparam", intParam); + histogram1TagList.Add("boolparam", boolParam); + + _histogram1Instrument.Record(counterValue, tagList: histogram1TagList); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicHistogram_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..efd90993 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,139 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.ObservableCounter? _observableCounterInstrument = null; + System.Diagnostics.Metrics.ObservableCounter? _observableCounter2Instrument = null; + System.Diagnostics.Metrics.ObservableCounter? _observableCounter3Instrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-observable-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-observable-meter", version: null); +#endif + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableCounter(System.Func f, int intParam, bool boolParam) + { + if (_observableCounterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableCounterTagList = new System.Diagnostics.TagList(); + + observableCounterTagList.Add("intparam", intParam); + observableCounterTagList.Add("boolparam", boolParam); + + _observableCounterInstrument = _meter.CreateObservableCounter("observablecounter", f, unit: null, description: null +#if !NET7_0 + , tags: observableCounterTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableCounter2(System.Func> f, int intParam, bool boolParam) + { + if (_observableCounter2Instrument != null) + { + throw new System.Exception("observablecounter2 has already been initialized."); + } + + System.Diagnostics.TagList observableCounter2TagList = new System.Diagnostics.TagList(); + + observableCounter2TagList.Add("intparam", intParam); + observableCounter2TagList.Add("boolparam", boolParam); + + _observableCounter2Instrument = _meter.CreateObservableCounter("observablecounter2", f, unit: null, description: null +#if !NET7_0 + , tags: observableCounter2TagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableCounter3(System.Func>> f, int intParam, bool boolParam) + { + if (_observableCounter3Instrument != null) + { + return; + } + + System.Diagnostics.TagList observableCounter3TagList = new System.Diagnostics.TagList(); + + observableCounter3TagList.Add("intparam", intParam); + observableCounter3TagList.Add("boolparam", boolParam); + + _observableCounter3Instrument = _meter.CreateObservableCounter("observablecounter3", f, unit: null, description: null +#if !NET7_0 + , tags: observableCounter3TagList +#endif + ); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableCounters_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..359ed017 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,139 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.ObservableGauge? _observableGaugeInstrument = null; + System.Diagnostics.Metrics.ObservableGauge? _observableGauge2Instrument = null; + System.Diagnostics.Metrics.ObservableGauge? _observableGauge3Instrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableGauge(System.Func f, int intParam, bool boolParam) + { + if (_observableGaugeInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableGaugeTagList = new System.Diagnostics.TagList(); + + observableGaugeTagList.Add("intparam", intParam); + observableGaugeTagList.Add("boolparam", boolParam); + + _observableGaugeInstrument = _meter.CreateObservableGauge("observablegauge", f, unit: null, description: null +#if !NET7_0 + , tags: observableGaugeTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableGauge2(System.Func> f, int intParam, bool boolParam) + { + if (_observableGauge2Instrument != null) + { + throw new System.Exception("observablegauge2 has already been initialized."); + } + + System.Diagnostics.TagList observableGauge2TagList = new System.Diagnostics.TagList(); + + observableGauge2TagList.Add("intparam", intParam); + observableGauge2TagList.Add("boolparam", boolParam); + + _observableGauge2Instrument = _meter.CreateObservableGauge("observablegauge2", f, unit: null, description: null +#if !NET7_0 + , tags: observableGauge2TagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableGauge3(System.Func>> f, int intParam, bool boolParam) + { + if (_observableGauge3Instrument != null) + { + return; + } + + System.Diagnostics.TagList observableGauge3TagList = new System.Diagnostics.TagList(); + + observableGauge3TagList.Add("intparam", intParam); + observableGauge3TagList.Add("boolparam", boolParam); + + _observableGauge3Instrument = _meter.CreateObservableGauge("observablegauge3", f, unit: null, description: null +#if !NET7_0 + , tags: observableGauge3TagList +#endif + ); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableGauge_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..72da1ea7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,139 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.ObservableUpDownCounter? _observableUpDownInstrument = null; + System.Diagnostics.Metrics.ObservableUpDownCounter? _observableUpDown2Instrument = null; + System.Diagnostics.Metrics.ObservableUpDownCounter? _observableUpDown3Instrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-observable-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-observable-meter", version: null); +#endif + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableUpDown(System.Func f, int intParam, bool boolParam) + { + if (_observableUpDownInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableUpDownTagList = new System.Diagnostics.TagList(); + + observableUpDownTagList.Add("intparam", intParam); + observableUpDownTagList.Add("boolparam", boolParam); + + _observableUpDownInstrument = _meter.CreateObservableUpDownCounter("observableupdown", f, unit: null, description: null +#if !NET7_0 + , tags: observableUpDownTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableUpDown2(System.Func> f, int intParam, bool boolParam) + { + if (_observableUpDown2Instrument != null) + { + throw new System.Exception("observableupdown2 has already been initialized."); + } + + System.Diagnostics.TagList observableUpDown2TagList = new System.Diagnostics.TagList(); + + observableUpDown2TagList.Add("intparam", intParam); + observableUpDown2TagList.Add("boolparam", boolParam); + + _observableUpDown2Instrument = _meter.CreateObservableUpDownCounter("observableupdown2", f, unit: null, description: null +#if !NET7_0 + , tags: observableUpDown2TagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableUpDown3(System.Func>> f, int intParam, bool boolParam) + { + if (_observableUpDown3Instrument != null) + { + return; + } + + System.Diagnostics.TagList observableUpDown3TagList = new System.Diagnostics.TagList(); + + observableUpDown3TagList.Add("intparam", intParam); + observableUpDown3TagList.Add("boolparam", boolParam); + + _observableUpDown3Instrument = _meter.CreateObservableUpDownCounter("observableupdown3", f, unit: null, description: null +#if !NET7_0 + , tags: observableUpDown3TagList +#endif + ); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicObservableUpDown_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..bf91060a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,142 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.UpDownCounter? _upDownInstrument = null; + System.Diagnostics.Metrics.UpDownCounter? _upDown2Instrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary upDownTags = new System.Collections.Generic.Dictionary(); + + PopulateUpDownTags(upDownTags); + +#endif + + _upDownInstrument = _meter.CreateUpDownCounter(name: "updown", unit: null, description: null +#if !NET7_0 + , tags: upDownTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary upDown2Tags = new System.Collections.Generic.Dictionary(); + + PopulateUpDown2Tags(upDown2Tags); + +#endif + + _upDown2Instrument = _meter.CreateUpDownCounter(name: "updown2", unit: null, description: null +#if !NET7_0 + , tags: upDown2Tags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateUpDownTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateUpDown2Tags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void UpDown(int counterValue, int intParam, bool boolParam) + { + if (_upDownInstrument == null) + { + return; + } + + System.Diagnostics.TagList upDownTagList = new System.Diagnostics.TagList(); + + upDownTagList.Add("intparam", intParam); + upDownTagList.Add("boolparam", boolParam); + + _upDownInstrument.Add(counterValue, tagList: upDownTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void UpDown2(int counterValue, int intParam, bool boolParam) + { + if (_upDown2Instrument == null) + { + return; + } + + System.Diagnostics.TagList upDown2TagList = new System.Diagnostics.TagList(); + + upDown2TagList.Add("intparam", intParam); + upDown2TagList.Add("boolparam", boolParam); + + _upDown2Instrument.Add(counterValue, tagList: upDown2TagList); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenBasicUpDown_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..e30e13a5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,109 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _counterInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary counterTags = new System.Collections.Generic.Dictionary(); + + PopulateCounterTags(counterTags); + +#endif + + _counterInstrument = _meter.CreateCounter(name: "counter", unit: null, description: null +#if !NET7_0 + , tags: counterTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter(int counterValue, int intParam, bool boolParam) + { + if (_counterInstrument == null) + { + return; + } + + System.Diagnostics.TagList counterTagList = new System.Diagnostics.TagList(); + + counterTagList.Add("intparam", intParam); + counterTagList.Add("boolparam", boolParam); + + _counterInstrument.Add(counterValue, tagList: counterTagList); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCoreDIExtension.DependencyInjection.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCoreDIExtension.DependencyInjection.g.verified.cs new file mode 100644 index 00000000..eb07be04 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCoreDIExtension.DependencyInjection.g.verified.cs @@ -0,0 +1,27 @@ +//HintName: Testing.TestMetricsCoreDIExtension.DependencyInjection.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Microsoft.Extensions.DependencyInjection +{ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + static class TestMetricsCoreDIExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static public Microsoft.Extensions.DependencyInjection.IServiceCollection AddTestMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) + { + return services.AddSingleton(); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIDisabledAtAssemblyAndInterfaceEnableDI_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..e30e13a5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,109 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _counterInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary counterTags = new System.Collections.Generic.Dictionary(); + + PopulateCounterTags(counterTags); + +#endif + + _counterInstrument = _meter.CreateCounter(name: "counter", unit: null, description: null +#if !NET7_0 + , tags: counterTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter(int counterValue, int intParam, bool boolParam) + { + if (_counterInstrument == null) + { + return; + } + + System.Diagnostics.TagList counterTagList = new System.Diagnostics.TagList(); + + counterTagList.Add("intparam", intParam); + counterTagList.Add("boolparam", boolParam); + + _counterInstrument.Add(counterValue, tagList: counterTagList); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenDIEnabledAtAssemblyAndInterfaceDisabledDI_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..e30e13a5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,109 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _counterInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary counterTags = new System.Collections.Generic.Dictionary(); + + PopulateCounterTags(counterTags); + +#endif + + _counterInstrument = _meter.CreateCounter(name: "counter", unit: null, description: null +#if !NET7_0 + , tags: counterTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter(int counterValue, int intParam, bool boolParam) + { + if (_counterInstrument == null) + { + return; + } + + System.Diagnostics.TagList counterTagList = new System.Diagnostics.TagList(); + + counterTagList.Add("intparam", intParam); + counterTagList.Add("boolparam", boolParam); + + _counterInstrument.Add(counterValue, tagList: counterTagList); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCoreDIExtension.DependencyInjection.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCoreDIExtension.DependencyInjection.g.verified.cs new file mode 100644 index 00000000..eb07be04 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCoreDIExtension.DependencyInjection.g.verified.cs @@ -0,0 +1,27 @@ +//HintName: Testing.TestMetricsCoreDIExtension.DependencyInjection.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Microsoft.Extensions.DependencyInjection +{ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + static class TestMetricsCoreDIExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static public Microsoft.Extensions.DependencyInjection.IServiceCollection AddTestMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) + { + return services.AddSingleton(); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenInterfaceEnableDI_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..8ffa1d0a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,296 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _autoCounterInstrument = null; + System.Diagnostics.Metrics.Counter? _counter_AutoIncrementInstrument = null; + System.Diagnostics.Metrics.Counter? _counterInstrument = null; + System.Diagnostics.Metrics.Histogram? _histogramInstrument = null; + System.Diagnostics.Metrics.UpDownCounter? _upDownCounterInstrument = null; + System.Diagnostics.Metrics.ObservableCounter? _observableCounterInstrument = null; + System.Diagnostics.Metrics.ObservableGauge? _observableGaugeInstrument = null; + System.Diagnostics.Metrics.ObservableUpDownCounter? _observableUpDownCounterInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoCounterTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoCounterTags(autoCounterTags); + +#endif + + _autoCounterInstrument = _meter.CreateCounter(name: "autocounter", unit: null, description: null +#if !NET7_0 + , tags: autoCounterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counter_AutoIncrementTags = new System.Collections.Generic.Dictionary(); + + PopulateCounter_AutoIncrementTags(counter_AutoIncrementTags); + +#endif + + _counter_AutoIncrementInstrument = _meter.CreateCounter(name: "counter_autoincrement", unit: null, description: null +#if !NET7_0 + , tags: counter_AutoIncrementTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counterTags = new System.Collections.Generic.Dictionary(); + + PopulateCounterTags(counterTags); + +#endif + + _counterInstrument = _meter.CreateCounter(name: "counter", unit: null, description: null +#if !NET7_0 + , tags: counterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary histogramTags = new System.Collections.Generic.Dictionary(); + + PopulateHistogramTags(histogramTags); + +#endif + + _histogramInstrument = _meter.CreateHistogram(name: "histogram", unit: null, description: null +#if !NET7_0 + , tags: histogramTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary upDownCounterTags = new System.Collections.Generic.Dictionary(); + + PopulateUpDownCounterTags(upDownCounterTags); + +#endif + + _upDownCounterInstrument = _meter.CreateUpDownCounter(name: "updowncounter", unit: null, description: null +#if !NET7_0 + , tags: upDownCounterTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounter_AutoIncrementTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateHistogramTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateUpDownCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoCounter(System.Collections.Generic.List genericParameter) + { + if (_autoCounterInstrument == null) + { + return; + } + + System.Diagnostics.TagList autoCounterTagList = new System.Diagnostics.TagList(); + + autoCounterTagList.Add("genericparameter", genericParameter); + + _autoCounterInstrument.Add(1, tagList: autoCounterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter_AutoIncrement(System.Collections.Generic.List genericParameter) + { + if (_counter_AutoIncrementInstrument == null) + { + return; + } + + System.Diagnostics.TagList counter_AutoIncrementTagList = new System.Diagnostics.TagList(); + + counter_AutoIncrementTagList.Add("genericparameter", genericParameter); + + _counter_AutoIncrementInstrument.Add(1, tagList: counter_AutoIncrementTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter(int value, System.Collections.Generic.List genericParameter) + { + if (_counterInstrument == null) + { + return; + } + + System.Diagnostics.TagList counterTagList = new System.Diagnostics.TagList(); + + counterTagList.Add("genericparameter", genericParameter); + + _counterInstrument.Add(value, tagList: counterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Histogram(int value, System.Collections.Generic.List genericParameter) + { + if (_histogramInstrument == null) + { + return; + } + + System.Diagnostics.TagList histogramTagList = new System.Diagnostics.TagList(); + + histogramTagList.Add("genericparameter", genericParameter); + + _histogramInstrument.Record(value, tagList: histogramTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void UpDownCounter(int value, System.Collections.Generic.List genericParameter) + { + if (_upDownCounterInstrument == null) + { + return; + } + + System.Diagnostics.TagList upDownCounterTagList = new System.Diagnostics.TagList(); + + upDownCounterTagList.Add("genericparameter", genericParameter); + + _upDownCounterInstrument.Add(value, tagList: upDownCounterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableCounter(System.Func valueFunc, System.Collections.Generic.List genericParameter) + { + if (_observableCounterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableCounterTagList = new System.Diagnostics.TagList(); + + observableCounterTagList.Add("genericparameter", genericParameter); + + _observableCounterInstrument = _meter.CreateObservableCounter("observablecounter", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableCounterTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableGauge(System.Func valueFunc, System.Collections.Generic.List genericParameter) + { + if (_observableGaugeInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableGaugeTagList = new System.Diagnostics.TagList(); + + observableGaugeTagList.Add("genericparameter", genericParameter); + + _observableGaugeInstrument = _meter.CreateObservableGauge("observablegauge", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableGaugeTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableUpDownCounter(System.Func valueFunc, System.Collections.Generic.List genericParameter) + { + if (_observableUpDownCounterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableUpDownCounterTagList = new System.Diagnostics.TagList(); + + observableUpDownCounterTagList.Add("genericparameter", genericParameter); + + _observableUpDownCounterInstrument = _meter.CreateObservableUpDownCounter("observableupdowncounter", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableUpDownCounterTagList +#endif + ); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_119ad5f9543409fa.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..2ba6359a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,296 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _autoCounterInstrument = null; + System.Diagnostics.Metrics.Counter? _counter_AutoIncrementInstrument = null; + System.Diagnostics.Metrics.Counter? _counterInstrument = null; + System.Diagnostics.Metrics.Histogram? _histogramInstrument = null; + System.Diagnostics.Metrics.UpDownCounter? _upDownCounterInstrument = null; + System.Diagnostics.Metrics.ObservableCounter? _observableCounterInstrument = null; + System.Diagnostics.Metrics.ObservableGauge? _observableGaugeInstrument = null; + System.Diagnostics.Metrics.ObservableUpDownCounter? _observableUpDownCounterInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoCounterTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoCounterTags(autoCounterTags); + +#endif + + _autoCounterInstrument = _meter.CreateCounter(name: "autocounter", unit: null, description: null +#if !NET7_0 + , tags: autoCounterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counter_AutoIncrementTags = new System.Collections.Generic.Dictionary(); + + PopulateCounter_AutoIncrementTags(counter_AutoIncrementTags); + +#endif + + _counter_AutoIncrementInstrument = _meter.CreateCounter(name: "counter_autoincrement", unit: null, description: null +#if !NET7_0 + , tags: counter_AutoIncrementTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counterTags = new System.Collections.Generic.Dictionary(); + + PopulateCounterTags(counterTags); + +#endif + + _counterInstrument = _meter.CreateCounter(name: "counter", unit: null, description: null +#if !NET7_0 + , tags: counterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary histogramTags = new System.Collections.Generic.Dictionary(); + + PopulateHistogramTags(histogramTags); + +#endif + + _histogramInstrument = _meter.CreateHistogram(name: "histogram", unit: null, description: null +#if !NET7_0 + , tags: histogramTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary upDownCounterTags = new System.Collections.Generic.Dictionary(); + + PopulateUpDownCounterTags(upDownCounterTags); + +#endif + + _upDownCounterInstrument = _meter.CreateUpDownCounter(name: "updowncounter", unit: null, description: null +#if !NET7_0 + , tags: upDownCounterTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounter_AutoIncrementTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateHistogramTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateUpDownCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoCounter(System.Collections.Generic.IDictionary genericParameter) + { + if (_autoCounterInstrument == null) + { + return; + } + + System.Diagnostics.TagList autoCounterTagList = new System.Diagnostics.TagList(); + + autoCounterTagList.Add("genericparameter", genericParameter); + + _autoCounterInstrument.Add(1, tagList: autoCounterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter_AutoIncrement(System.Collections.Generic.IDictionary genericParameter) + { + if (_counter_AutoIncrementInstrument == null) + { + return; + } + + System.Diagnostics.TagList counter_AutoIncrementTagList = new System.Diagnostics.TagList(); + + counter_AutoIncrementTagList.Add("genericparameter", genericParameter); + + _counter_AutoIncrementInstrument.Add(1, tagList: counter_AutoIncrementTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter(int value, System.Collections.Generic.IDictionary genericParameter) + { + if (_counterInstrument == null) + { + return; + } + + System.Diagnostics.TagList counterTagList = new System.Diagnostics.TagList(); + + counterTagList.Add("genericparameter", genericParameter); + + _counterInstrument.Add(value, tagList: counterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Histogram(int value, System.Collections.Generic.IDictionary genericParameter) + { + if (_histogramInstrument == null) + { + return; + } + + System.Diagnostics.TagList histogramTagList = new System.Diagnostics.TagList(); + + histogramTagList.Add("genericparameter", genericParameter); + + _histogramInstrument.Record(value, tagList: histogramTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void UpDownCounter(int value, System.Collections.Generic.IDictionary genericParameter) + { + if (_upDownCounterInstrument == null) + { + return; + } + + System.Diagnostics.TagList upDownCounterTagList = new System.Diagnostics.TagList(); + + upDownCounterTagList.Add("genericparameter", genericParameter); + + _upDownCounterInstrument.Add(value, tagList: upDownCounterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableCounter(System.Func valueFunc, System.Collections.Generic.IDictionary genericParameter) + { + if (_observableCounterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableCounterTagList = new System.Diagnostics.TagList(); + + observableCounterTagList.Add("genericparameter", genericParameter); + + _observableCounterInstrument = _meter.CreateObservableCounter("observablecounter", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableCounterTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableGauge(System.Func valueFunc, System.Collections.Generic.IDictionary genericParameter) + { + if (_observableGaugeInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableGaugeTagList = new System.Diagnostics.TagList(); + + observableGaugeTagList.Add("genericparameter", genericParameter); + + _observableGaugeInstrument = _meter.CreateObservableGauge("observablegauge", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableGaugeTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableUpDownCounter(System.Func valueFunc, System.Collections.Generic.IDictionary genericParameter) + { + if (_observableUpDownCounterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableUpDownCounterTagList = new System.Diagnostics.TagList(); + + observableUpDownCounterTagList.Add("genericparameter", genericParameter); + + _observableUpDownCounterInstrument = _meter.CreateObservableUpDownCounter("observableupdowncounter", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableUpDownCounterTagList +#endif + ); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_8b85c327c951ae9d.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..5479c47d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,296 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _autoCounterInstrument = null; + System.Diagnostics.Metrics.Counter? _counter_AutoIncrementInstrument = null; + System.Diagnostics.Metrics.Counter? _counterInstrument = null; + System.Diagnostics.Metrics.Histogram? _histogramInstrument = null; + System.Diagnostics.Metrics.UpDownCounter? _upDownCounterInstrument = null; + System.Diagnostics.Metrics.ObservableCounter? _observableCounterInstrument = null; + System.Diagnostics.Metrics.ObservableGauge? _observableGaugeInstrument = null; + System.Diagnostics.Metrics.ObservableUpDownCounter? _observableUpDownCounterInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoCounterTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoCounterTags(autoCounterTags); + +#endif + + _autoCounterInstrument = _meter.CreateCounter(name: "autocounter", unit: null, description: null +#if !NET7_0 + , tags: autoCounterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counter_AutoIncrementTags = new System.Collections.Generic.Dictionary(); + + PopulateCounter_AutoIncrementTags(counter_AutoIncrementTags); + +#endif + + _counter_AutoIncrementInstrument = _meter.CreateCounter(name: "counter_autoincrement", unit: null, description: null +#if !NET7_0 + , tags: counter_AutoIncrementTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counterTags = new System.Collections.Generic.Dictionary(); + + PopulateCounterTags(counterTags); + +#endif + + _counterInstrument = _meter.CreateCounter(name: "counter", unit: null, description: null +#if !NET7_0 + , tags: counterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary histogramTags = new System.Collections.Generic.Dictionary(); + + PopulateHistogramTags(histogramTags); + +#endif + + _histogramInstrument = _meter.CreateHistogram(name: "histogram", unit: null, description: null +#if !NET7_0 + , tags: histogramTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary upDownCounterTags = new System.Collections.Generic.Dictionary(); + + PopulateUpDownCounterTags(upDownCounterTags); + +#endif + + _upDownCounterInstrument = _meter.CreateUpDownCounter(name: "updowncounter", unit: null, description: null +#if !NET7_0 + , tags: upDownCounterTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounter_AutoIncrementTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateHistogramTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateUpDownCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoCounter(System.Collections.Generic.Dictionary genericParameter) + { + if (_autoCounterInstrument == null) + { + return; + } + + System.Diagnostics.TagList autoCounterTagList = new System.Diagnostics.TagList(); + + autoCounterTagList.Add("genericparameter", genericParameter); + + _autoCounterInstrument.Add(1, tagList: autoCounterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter_AutoIncrement(System.Collections.Generic.Dictionary genericParameter) + { + if (_counter_AutoIncrementInstrument == null) + { + return; + } + + System.Diagnostics.TagList counter_AutoIncrementTagList = new System.Diagnostics.TagList(); + + counter_AutoIncrementTagList.Add("genericparameter", genericParameter); + + _counter_AutoIncrementInstrument.Add(1, tagList: counter_AutoIncrementTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter(int value, System.Collections.Generic.Dictionary genericParameter) + { + if (_counterInstrument == null) + { + return; + } + + System.Diagnostics.TagList counterTagList = new System.Diagnostics.TagList(); + + counterTagList.Add("genericparameter", genericParameter); + + _counterInstrument.Add(value, tagList: counterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Histogram(int value, System.Collections.Generic.Dictionary genericParameter) + { + if (_histogramInstrument == null) + { + return; + } + + System.Diagnostics.TagList histogramTagList = new System.Diagnostics.TagList(); + + histogramTagList.Add("genericparameter", genericParameter); + + _histogramInstrument.Record(value, tagList: histogramTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void UpDownCounter(int value, System.Collections.Generic.Dictionary genericParameter) + { + if (_upDownCounterInstrument == null) + { + return; + } + + System.Diagnostics.TagList upDownCounterTagList = new System.Diagnostics.TagList(); + + upDownCounterTagList.Add("genericparameter", genericParameter); + + _upDownCounterInstrument.Add(value, tagList: upDownCounterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableCounter(System.Func valueFunc, System.Collections.Generic.Dictionary genericParameter) + { + if (_observableCounterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableCounterTagList = new System.Diagnostics.TagList(); + + observableCounterTagList.Add("genericparameter", genericParameter); + + _observableCounterInstrument = _meter.CreateObservableCounter("observablecounter", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableCounterTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableGauge(System.Func valueFunc, System.Collections.Generic.Dictionary genericParameter) + { + if (_observableGaugeInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableGaugeTagList = new System.Diagnostics.TagList(); + + observableGaugeTagList.Add("genericparameter", genericParameter); + + _observableGaugeInstrument = _meter.CreateObservableGauge("observablegauge", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableGaugeTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableUpDownCounter(System.Func valueFunc, System.Collections.Generic.Dictionary genericParameter) + { + if (_observableUpDownCounterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableUpDownCounterTagList = new System.Diagnostics.TagList(); + + observableUpDownCounterTagList.Add("genericparameter", genericParameter); + + _observableUpDownCounterInstrument = _meter.CreateObservableUpDownCounter("observableupdowncounter", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableUpDownCounterTagList +#endif + ); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_d1d80d121fcec7e9.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..2ee833da --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,296 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _autoCounterInstrument = null; + System.Diagnostics.Metrics.Counter? _counter_AutoIncrementInstrument = null; + System.Diagnostics.Metrics.Counter? _counterInstrument = null; + System.Diagnostics.Metrics.Histogram? _histogramInstrument = null; + System.Diagnostics.Metrics.UpDownCounter? _upDownCounterInstrument = null; + System.Diagnostics.Metrics.ObservableCounter? _observableCounterInstrument = null; + System.Diagnostics.Metrics.ObservableGauge? _observableGaugeInstrument = null; + System.Diagnostics.Metrics.ObservableUpDownCounter? _observableUpDownCounterInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoCounterTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoCounterTags(autoCounterTags); + +#endif + + _autoCounterInstrument = _meter.CreateCounter(name: "autocounter", unit: null, description: null +#if !NET7_0 + , tags: autoCounterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counter_AutoIncrementTags = new System.Collections.Generic.Dictionary(); + + PopulateCounter_AutoIncrementTags(counter_AutoIncrementTags); + +#endif + + _counter_AutoIncrementInstrument = _meter.CreateCounter(name: "counter_autoincrement", unit: null, description: null +#if !NET7_0 + , tags: counter_AutoIncrementTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counterTags = new System.Collections.Generic.Dictionary(); + + PopulateCounterTags(counterTags); + +#endif + + _counterInstrument = _meter.CreateCounter(name: "counter", unit: null, description: null +#if !NET7_0 + , tags: counterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary histogramTags = new System.Collections.Generic.Dictionary(); + + PopulateHistogramTags(histogramTags); + +#endif + + _histogramInstrument = _meter.CreateHistogram(name: "histogram", unit: null, description: null +#if !NET7_0 + , tags: histogramTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary upDownCounterTags = new System.Collections.Generic.Dictionary(); + + PopulateUpDownCounterTags(upDownCounterTags); + +#endif + + _upDownCounterInstrument = _meter.CreateUpDownCounter(name: "updowncounter", unit: null, description: null +#if !NET7_0 + , tags: upDownCounterTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounter_AutoIncrementTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateHistogramTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateUpDownCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoCounter(System.Collections.Generic.IEnumerable genericParameter) + { + if (_autoCounterInstrument == null) + { + return; + } + + System.Diagnostics.TagList autoCounterTagList = new System.Diagnostics.TagList(); + + autoCounterTagList.Add("genericparameter", genericParameter); + + _autoCounterInstrument.Add(1, tagList: autoCounterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter_AutoIncrement(System.Collections.Generic.IEnumerable genericParameter) + { + if (_counter_AutoIncrementInstrument == null) + { + return; + } + + System.Diagnostics.TagList counter_AutoIncrementTagList = new System.Diagnostics.TagList(); + + counter_AutoIncrementTagList.Add("genericparameter", genericParameter); + + _counter_AutoIncrementInstrument.Add(1, tagList: counter_AutoIncrementTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter(int value, System.Collections.Generic.IEnumerable genericParameter) + { + if (_counterInstrument == null) + { + return; + } + + System.Diagnostics.TagList counterTagList = new System.Diagnostics.TagList(); + + counterTagList.Add("genericparameter", genericParameter); + + _counterInstrument.Add(value, tagList: counterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Histogram(int value, System.Collections.Generic.IEnumerable genericParameter) + { + if (_histogramInstrument == null) + { + return; + } + + System.Diagnostics.TagList histogramTagList = new System.Diagnostics.TagList(); + + histogramTagList.Add("genericparameter", genericParameter); + + _histogramInstrument.Record(value, tagList: histogramTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void UpDownCounter(int value, System.Collections.Generic.IEnumerable genericParameter) + { + if (_upDownCounterInstrument == null) + { + return; + } + + System.Diagnostics.TagList upDownCounterTagList = new System.Diagnostics.TagList(); + + upDownCounterTagList.Add("genericparameter", genericParameter); + + _upDownCounterInstrument.Add(value, tagList: upDownCounterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableCounter(System.Func valueFunc, System.Collections.Generic.IEnumerable genericParameter) + { + if (_observableCounterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableCounterTagList = new System.Diagnostics.TagList(); + + observableCounterTagList.Add("genericparameter", genericParameter); + + _observableCounterInstrument = _meter.CreateObservableCounter("observablecounter", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableCounterTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableGauge(System.Func valueFunc, System.Collections.Generic.IEnumerable genericParameter) + { + if (_observableGaugeInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableGaugeTagList = new System.Diagnostics.TagList(); + + observableGaugeTagList.Add("genericparameter", genericParameter); + + _observableGaugeInstrument = _meter.CreateObservableGauge("observablegauge", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableGaugeTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableUpDownCounter(System.Func valueFunc, System.Collections.Generic.IEnumerable genericParameter) + { + if (_observableUpDownCounterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableUpDownCounterTagList = new System.Diagnostics.TagList(); + + observableUpDownCounterTagList.Add("genericparameter", genericParameter); + + _observableUpDownCounterInstrument = _meter.CreateObservableUpDownCounter("observableupdowncounter", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableUpDownCounterTagList +#endif + ); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_f08efd51efbba703.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..5479c47d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,296 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _autoCounterInstrument = null; + System.Diagnostics.Metrics.Counter? _counter_AutoIncrementInstrument = null; + System.Diagnostics.Metrics.Counter? _counterInstrument = null; + System.Diagnostics.Metrics.Histogram? _histogramInstrument = null; + System.Diagnostics.Metrics.UpDownCounter? _upDownCounterInstrument = null; + System.Diagnostics.Metrics.ObservableCounter? _observableCounterInstrument = null; + System.Diagnostics.Metrics.ObservableGauge? _observableGaugeInstrument = null; + System.Diagnostics.Metrics.ObservableUpDownCounter? _observableUpDownCounterInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoCounterTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoCounterTags(autoCounterTags); + +#endif + + _autoCounterInstrument = _meter.CreateCounter(name: "autocounter", unit: null, description: null +#if !NET7_0 + , tags: autoCounterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counter_AutoIncrementTags = new System.Collections.Generic.Dictionary(); + + PopulateCounter_AutoIncrementTags(counter_AutoIncrementTags); + +#endif + + _counter_AutoIncrementInstrument = _meter.CreateCounter(name: "counter_autoincrement", unit: null, description: null +#if !NET7_0 + , tags: counter_AutoIncrementTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counterTags = new System.Collections.Generic.Dictionary(); + + PopulateCounterTags(counterTags); + +#endif + + _counterInstrument = _meter.CreateCounter(name: "counter", unit: null, description: null +#if !NET7_0 + , tags: counterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary histogramTags = new System.Collections.Generic.Dictionary(); + + PopulateHistogramTags(histogramTags); + +#endif + + _histogramInstrument = _meter.CreateHistogram(name: "histogram", unit: null, description: null +#if !NET7_0 + , tags: histogramTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary upDownCounterTags = new System.Collections.Generic.Dictionary(); + + PopulateUpDownCounterTags(upDownCounterTags); + +#endif + + _upDownCounterInstrument = _meter.CreateUpDownCounter(name: "updowncounter", unit: null, description: null +#if !NET7_0 + , tags: upDownCounterTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounter_AutoIncrementTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateHistogramTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateUpDownCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoCounter(System.Collections.Generic.Dictionary genericParameter) + { + if (_autoCounterInstrument == null) + { + return; + } + + System.Diagnostics.TagList autoCounterTagList = new System.Diagnostics.TagList(); + + autoCounterTagList.Add("genericparameter", genericParameter); + + _autoCounterInstrument.Add(1, tagList: autoCounterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter_AutoIncrement(System.Collections.Generic.Dictionary genericParameter) + { + if (_counter_AutoIncrementInstrument == null) + { + return; + } + + System.Diagnostics.TagList counter_AutoIncrementTagList = new System.Diagnostics.TagList(); + + counter_AutoIncrementTagList.Add("genericparameter", genericParameter); + + _counter_AutoIncrementInstrument.Add(1, tagList: counter_AutoIncrementTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter(int value, System.Collections.Generic.Dictionary genericParameter) + { + if (_counterInstrument == null) + { + return; + } + + System.Diagnostics.TagList counterTagList = new System.Diagnostics.TagList(); + + counterTagList.Add("genericparameter", genericParameter); + + _counterInstrument.Add(value, tagList: counterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Histogram(int value, System.Collections.Generic.Dictionary genericParameter) + { + if (_histogramInstrument == null) + { + return; + } + + System.Diagnostics.TagList histogramTagList = new System.Diagnostics.TagList(); + + histogramTagList.Add("genericparameter", genericParameter); + + _histogramInstrument.Record(value, tagList: histogramTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void UpDownCounter(int value, System.Collections.Generic.Dictionary genericParameter) + { + if (_upDownCounterInstrument == null) + { + return; + } + + System.Diagnostics.TagList upDownCounterTagList = new System.Diagnostics.TagList(); + + upDownCounterTagList.Add("genericparameter", genericParameter); + + _upDownCounterInstrument.Add(value, tagList: upDownCounterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableCounter(System.Func valueFunc, System.Collections.Generic.Dictionary genericParameter) + { + if (_observableCounterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableCounterTagList = new System.Diagnostics.TagList(); + + observableCounterTagList.Add("genericparameter", genericParameter); + + _observableCounterInstrument = _meter.CreateObservableCounter("observablecounter", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableCounterTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableGauge(System.Func valueFunc, System.Collections.Generic.Dictionary genericParameter) + { + if (_observableGaugeInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableGaugeTagList = new System.Diagnostics.TagList(); + + observableGaugeTagList.Add("genericparameter", genericParameter); + + _observableGaugeInstrument = _meter.CreateObservableGauge("observablegauge", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableGaugeTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableUpDownCounter(System.Func valueFunc, System.Collections.Generic.Dictionary genericParameter) + { + if (_observableUpDownCounterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableUpDownCounterTagList = new System.Diagnostics.TagList(); + + observableUpDownCounterTagList.Add("genericparameter", genericParameter); + + _observableUpDownCounterInstrument = _meter.CreateObservableUpDownCounter("observableupdowncounter", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableUpDownCounterTagList +#endif + ); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.Dictionary-string,int-.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..2ba6359a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,296 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _autoCounterInstrument = null; + System.Diagnostics.Metrics.Counter? _counter_AutoIncrementInstrument = null; + System.Diagnostics.Metrics.Counter? _counterInstrument = null; + System.Diagnostics.Metrics.Histogram? _histogramInstrument = null; + System.Diagnostics.Metrics.UpDownCounter? _upDownCounterInstrument = null; + System.Diagnostics.Metrics.ObservableCounter? _observableCounterInstrument = null; + System.Diagnostics.Metrics.ObservableGauge? _observableGaugeInstrument = null; + System.Diagnostics.Metrics.ObservableUpDownCounter? _observableUpDownCounterInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoCounterTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoCounterTags(autoCounterTags); + +#endif + + _autoCounterInstrument = _meter.CreateCounter(name: "autocounter", unit: null, description: null +#if !NET7_0 + , tags: autoCounterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counter_AutoIncrementTags = new System.Collections.Generic.Dictionary(); + + PopulateCounter_AutoIncrementTags(counter_AutoIncrementTags); + +#endif + + _counter_AutoIncrementInstrument = _meter.CreateCounter(name: "counter_autoincrement", unit: null, description: null +#if !NET7_0 + , tags: counter_AutoIncrementTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counterTags = new System.Collections.Generic.Dictionary(); + + PopulateCounterTags(counterTags); + +#endif + + _counterInstrument = _meter.CreateCounter(name: "counter", unit: null, description: null +#if !NET7_0 + , tags: counterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary histogramTags = new System.Collections.Generic.Dictionary(); + + PopulateHistogramTags(histogramTags); + +#endif + + _histogramInstrument = _meter.CreateHistogram(name: "histogram", unit: null, description: null +#if !NET7_0 + , tags: histogramTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary upDownCounterTags = new System.Collections.Generic.Dictionary(); + + PopulateUpDownCounterTags(upDownCounterTags); + +#endif + + _upDownCounterInstrument = _meter.CreateUpDownCounter(name: "updowncounter", unit: null, description: null +#if !NET7_0 + , tags: upDownCounterTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounter_AutoIncrementTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateHistogramTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateUpDownCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoCounter(System.Collections.Generic.IDictionary genericParameter) + { + if (_autoCounterInstrument == null) + { + return; + } + + System.Diagnostics.TagList autoCounterTagList = new System.Diagnostics.TagList(); + + autoCounterTagList.Add("genericparameter", genericParameter); + + _autoCounterInstrument.Add(1, tagList: autoCounterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter_AutoIncrement(System.Collections.Generic.IDictionary genericParameter) + { + if (_counter_AutoIncrementInstrument == null) + { + return; + } + + System.Diagnostics.TagList counter_AutoIncrementTagList = new System.Diagnostics.TagList(); + + counter_AutoIncrementTagList.Add("genericparameter", genericParameter); + + _counter_AutoIncrementInstrument.Add(1, tagList: counter_AutoIncrementTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter(int value, System.Collections.Generic.IDictionary genericParameter) + { + if (_counterInstrument == null) + { + return; + } + + System.Diagnostics.TagList counterTagList = new System.Diagnostics.TagList(); + + counterTagList.Add("genericparameter", genericParameter); + + _counterInstrument.Add(value, tagList: counterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Histogram(int value, System.Collections.Generic.IDictionary genericParameter) + { + if (_histogramInstrument == null) + { + return; + } + + System.Diagnostics.TagList histogramTagList = new System.Diagnostics.TagList(); + + histogramTagList.Add("genericparameter", genericParameter); + + _histogramInstrument.Record(value, tagList: histogramTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void UpDownCounter(int value, System.Collections.Generic.IDictionary genericParameter) + { + if (_upDownCounterInstrument == null) + { + return; + } + + System.Diagnostics.TagList upDownCounterTagList = new System.Diagnostics.TagList(); + + upDownCounterTagList.Add("genericparameter", genericParameter); + + _upDownCounterInstrument.Add(value, tagList: upDownCounterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableCounter(System.Func valueFunc, System.Collections.Generic.IDictionary genericParameter) + { + if (_observableCounterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableCounterTagList = new System.Diagnostics.TagList(); + + observableCounterTagList.Add("genericparameter", genericParameter); + + _observableCounterInstrument = _meter.CreateObservableCounter("observablecounter", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableCounterTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableGauge(System.Func valueFunc, System.Collections.Generic.IDictionary genericParameter) + { + if (_observableGaugeInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableGaugeTagList = new System.Diagnostics.TagList(); + + observableGaugeTagList.Add("genericparameter", genericParameter); + + _observableGaugeInstrument = _meter.CreateObservableGauge("observablegauge", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableGaugeTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableUpDownCounter(System.Func valueFunc, System.Collections.Generic.IDictionary genericParameter) + { + if (_observableUpDownCounterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableUpDownCounterTagList = new System.Diagnostics.TagList(); + + observableUpDownCounterTagList.Add("genericparameter", genericParameter); + + _observableUpDownCounterInstrument = _meter.CreateObservableUpDownCounter("observableupdowncounter", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableUpDownCounterTagList +#endif + ); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IDictionary-string,int-.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..2ee833da --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,296 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _autoCounterInstrument = null; + System.Diagnostics.Metrics.Counter? _counter_AutoIncrementInstrument = null; + System.Diagnostics.Metrics.Counter? _counterInstrument = null; + System.Diagnostics.Metrics.Histogram? _histogramInstrument = null; + System.Diagnostics.Metrics.UpDownCounter? _upDownCounterInstrument = null; + System.Diagnostics.Metrics.ObservableCounter? _observableCounterInstrument = null; + System.Diagnostics.Metrics.ObservableGauge? _observableGaugeInstrument = null; + System.Diagnostics.Metrics.ObservableUpDownCounter? _observableUpDownCounterInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoCounterTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoCounterTags(autoCounterTags); + +#endif + + _autoCounterInstrument = _meter.CreateCounter(name: "autocounter", unit: null, description: null +#if !NET7_0 + , tags: autoCounterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counter_AutoIncrementTags = new System.Collections.Generic.Dictionary(); + + PopulateCounter_AutoIncrementTags(counter_AutoIncrementTags); + +#endif + + _counter_AutoIncrementInstrument = _meter.CreateCounter(name: "counter_autoincrement", unit: null, description: null +#if !NET7_0 + , tags: counter_AutoIncrementTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counterTags = new System.Collections.Generic.Dictionary(); + + PopulateCounterTags(counterTags); + +#endif + + _counterInstrument = _meter.CreateCounter(name: "counter", unit: null, description: null +#if !NET7_0 + , tags: counterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary histogramTags = new System.Collections.Generic.Dictionary(); + + PopulateHistogramTags(histogramTags); + +#endif + + _histogramInstrument = _meter.CreateHistogram(name: "histogram", unit: null, description: null +#if !NET7_0 + , tags: histogramTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary upDownCounterTags = new System.Collections.Generic.Dictionary(); + + PopulateUpDownCounterTags(upDownCounterTags); + +#endif + + _upDownCounterInstrument = _meter.CreateUpDownCounter(name: "updowncounter", unit: null, description: null +#if !NET7_0 + , tags: upDownCounterTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounter_AutoIncrementTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateHistogramTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateUpDownCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoCounter(System.Collections.Generic.IEnumerable genericParameter) + { + if (_autoCounterInstrument == null) + { + return; + } + + System.Diagnostics.TagList autoCounterTagList = new System.Diagnostics.TagList(); + + autoCounterTagList.Add("genericparameter", genericParameter); + + _autoCounterInstrument.Add(1, tagList: autoCounterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter_AutoIncrement(System.Collections.Generic.IEnumerable genericParameter) + { + if (_counter_AutoIncrementInstrument == null) + { + return; + } + + System.Diagnostics.TagList counter_AutoIncrementTagList = new System.Diagnostics.TagList(); + + counter_AutoIncrementTagList.Add("genericparameter", genericParameter); + + _counter_AutoIncrementInstrument.Add(1, tagList: counter_AutoIncrementTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter(int value, System.Collections.Generic.IEnumerable genericParameter) + { + if (_counterInstrument == null) + { + return; + } + + System.Diagnostics.TagList counterTagList = new System.Diagnostics.TagList(); + + counterTagList.Add("genericparameter", genericParameter); + + _counterInstrument.Add(value, tagList: counterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Histogram(int value, System.Collections.Generic.IEnumerable genericParameter) + { + if (_histogramInstrument == null) + { + return; + } + + System.Diagnostics.TagList histogramTagList = new System.Diagnostics.TagList(); + + histogramTagList.Add("genericparameter", genericParameter); + + _histogramInstrument.Record(value, tagList: histogramTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void UpDownCounter(int value, System.Collections.Generic.IEnumerable genericParameter) + { + if (_upDownCounterInstrument == null) + { + return; + } + + System.Diagnostics.TagList upDownCounterTagList = new System.Diagnostics.TagList(); + + upDownCounterTagList.Add("genericparameter", genericParameter); + + _upDownCounterInstrument.Add(value, tagList: upDownCounterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableCounter(System.Func valueFunc, System.Collections.Generic.IEnumerable genericParameter) + { + if (_observableCounterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableCounterTagList = new System.Diagnostics.TagList(); + + observableCounterTagList.Add("genericparameter", genericParameter); + + _observableCounterInstrument = _meter.CreateObservableCounter("observablecounter", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableCounterTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableGauge(System.Func valueFunc, System.Collections.Generic.IEnumerable genericParameter) + { + if (_observableGaugeInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableGaugeTagList = new System.Diagnostics.TagList(); + + observableGaugeTagList.Add("genericparameter", genericParameter); + + _observableGaugeInstrument = _meter.CreateObservableGauge("observablegauge", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableGaugeTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableUpDownCounter(System.Func valueFunc, System.Collections.Generic.IEnumerable genericParameter) + { + if (_observableUpDownCounterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableUpDownCounterTagList = new System.Diagnostics.TagList(); + + observableUpDownCounterTagList.Add("genericparameter", genericParameter); + + _observableUpDownCounterInstrument = _meter.CreateObservableUpDownCounter("observableupdowncounter", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableUpDownCounterTagList +#endif + ); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.IEnumerable-string-.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..8ffa1d0a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,296 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _autoCounterInstrument = null; + System.Diagnostics.Metrics.Counter? _counter_AutoIncrementInstrument = null; + System.Diagnostics.Metrics.Counter? _counterInstrument = null; + System.Diagnostics.Metrics.Histogram? _histogramInstrument = null; + System.Diagnostics.Metrics.UpDownCounter? _upDownCounterInstrument = null; + System.Diagnostics.Metrics.ObservableCounter? _observableCounterInstrument = null; + System.Diagnostics.Metrics.ObservableGauge? _observableGaugeInstrument = null; + System.Diagnostics.Metrics.ObservableUpDownCounter? _observableUpDownCounterInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoCounterTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoCounterTags(autoCounterTags); + +#endif + + _autoCounterInstrument = _meter.CreateCounter(name: "autocounter", unit: null, description: null +#if !NET7_0 + , tags: autoCounterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counter_AutoIncrementTags = new System.Collections.Generic.Dictionary(); + + PopulateCounter_AutoIncrementTags(counter_AutoIncrementTags); + +#endif + + _counter_AutoIncrementInstrument = _meter.CreateCounter(name: "counter_autoincrement", unit: null, description: null +#if !NET7_0 + , tags: counter_AutoIncrementTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counterTags = new System.Collections.Generic.Dictionary(); + + PopulateCounterTags(counterTags); + +#endif + + _counterInstrument = _meter.CreateCounter(name: "counter", unit: null, description: null +#if !NET7_0 + , tags: counterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary histogramTags = new System.Collections.Generic.Dictionary(); + + PopulateHistogramTags(histogramTags); + +#endif + + _histogramInstrument = _meter.CreateHistogram(name: "histogram", unit: null, description: null +#if !NET7_0 + , tags: histogramTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary upDownCounterTags = new System.Collections.Generic.Dictionary(); + + PopulateUpDownCounterTags(upDownCounterTags); + +#endif + + _upDownCounterInstrument = _meter.CreateUpDownCounter(name: "updowncounter", unit: null, description: null +#if !NET7_0 + , tags: upDownCounterTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounter_AutoIncrementTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateHistogramTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateUpDownCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoCounter(System.Collections.Generic.List genericParameter) + { + if (_autoCounterInstrument == null) + { + return; + } + + System.Diagnostics.TagList autoCounterTagList = new System.Diagnostics.TagList(); + + autoCounterTagList.Add("genericparameter", genericParameter); + + _autoCounterInstrument.Add(1, tagList: autoCounterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter_AutoIncrement(System.Collections.Generic.List genericParameter) + { + if (_counter_AutoIncrementInstrument == null) + { + return; + } + + System.Diagnostics.TagList counter_AutoIncrementTagList = new System.Diagnostics.TagList(); + + counter_AutoIncrementTagList.Add("genericparameter", genericParameter); + + _counter_AutoIncrementInstrument.Add(1, tagList: counter_AutoIncrementTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Counter(int value, System.Collections.Generic.List genericParameter) + { + if (_counterInstrument == null) + { + return; + } + + System.Diagnostics.TagList counterTagList = new System.Diagnostics.TagList(); + + counterTagList.Add("genericparameter", genericParameter); + + _counterInstrument.Add(value, tagList: counterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Histogram(int value, System.Collections.Generic.List genericParameter) + { + if (_histogramInstrument == null) + { + return; + } + + System.Diagnostics.TagList histogramTagList = new System.Diagnostics.TagList(); + + histogramTagList.Add("genericparameter", genericParameter); + + _histogramInstrument.Record(value, tagList: histogramTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void UpDownCounter(int value, System.Collections.Generic.List genericParameter) + { + if (_upDownCounterInstrument == null) + { + return; + } + + System.Diagnostics.TagList upDownCounterTagList = new System.Diagnostics.TagList(); + + upDownCounterTagList.Add("genericparameter", genericParameter); + + _upDownCounterInstrument.Add(value, tagList: upDownCounterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableCounter(System.Func valueFunc, System.Collections.Generic.List genericParameter) + { + if (_observableCounterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableCounterTagList = new System.Diagnostics.TagList(); + + observableCounterTagList.Add("genericparameter", genericParameter); + + _observableCounterInstrument = _meter.CreateObservableCounter("observablecounter", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableCounterTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableGauge(System.Func valueFunc, System.Collections.Generic.List genericParameter) + { + if (_observableGaugeInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableGaugeTagList = new System.Diagnostics.TagList(); + + observableGaugeTagList.Add("genericparameter", genericParameter); + + _observableGaugeInstrument = _meter.CreateObservableGauge("observablegauge", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableGaugeTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableUpDownCounter(System.Func valueFunc, System.Collections.Generic.List genericParameter) + { + if (_observableUpDownCounterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableUpDownCounterTagList = new System.Diagnostics.TagList(); + + observableUpDownCounterTagList.Add("genericparameter", genericParameter); + + _observableUpDownCounterInstrument = _meter.CreateObservableUpDownCounter("observableupdowncounter", valueFunc, unit: null, description: null +#if !NET7_0 + , tags: observableUpDownCounterTagList +#endif + ); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenMethodWithBasicGenericParams_GeneratesEntryCorrectly_parameterType=System.Collections.Generic.List-string-.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..9d659202 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _autoCounterMetricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoCounterMetricTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoCounterMetricTags(autoCounterMetricTags); + +#endif + + _autoCounterMetricInstrument = _meter.CreateCounter(name: "autocountermetric", unit: null, description: null +#if !NET7_0 + , tags: autoCounterMetricTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterMetricTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoCounterMetric() + { + if (_autoCounterMetricInstrument == null) + { + return; + } + + _autoCounterMetricInstrument.Add(1, tagList: default); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefaultLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..8c2dd195 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _autoCounterMetricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoCounterMetricTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoCounterMetricTags(autoCounterMetricTags); + +#endif + + _autoCounterMetricInstrument = _meter.CreateCounter(name: "AutoCounterMetric", unit: null, description: null +#if !NET7_0 + , tags: autoCounterMetricTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterMetricTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoCounterMetric() + { + if (_autoCounterMetricInstrument == null) + { + return; + } + + _autoCounterMetricInstrument.Add(1, tagList: default); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeDefinedCase_GeneratesMetricsWithLowercaseName.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..9d659202 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _autoCounterMetricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoCounterMetricTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoCounterMetricTags(autoCounterMetricTags); + +#endif + + _autoCounterMetricInstrument = _meter.CreateCounter(name: "autocountermetric", unit: null, description: null +#if !NET7_0 + , tags: autoCounterMetricTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterMetricTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoCounterMetric() + { + if (_autoCounterMetricInstrument == null) + { + return; + } + + _autoCounterMetricInstrument.Add(1, tagList: default); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameShouldBeLowerCase_GeneratesMetricsWithLowercaseName.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..fe880137 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,109 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.UpDownCounter? _metricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary metricTags = new System.Collections.Generic.Dictionary(); + + PopulateMetricTags(metricTags); + +#endif + + _metricInstrument = _meter.CreateUpDownCounter(name: "an-updown-counter-name-property", unit: "sponges-property", description: "sponge sales per-capita-property." +#if !NET7_0 + , tags: metricTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateMetricTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Metric(byte counterValue, int intParam, bool boolParam) + { + if (_metricInstrument == null) + { + return; + } + + System.Diagnostics.TagList metricTagList = new System.Diagnostics.TagList(); + + metricTagList.Add("intparam", intParam); + metricTagList.Add("boolparam", boolParam); + + _metricInstrument.Add(counterValue, tagList: metricTagList); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_4d563d35ed2bf12d.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..5e493a2a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,109 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _metricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary metricTags = new System.Collections.Generic.Dictionary(); + + PopulateMetricTags(metricTags); + +#endif + + _metricInstrument = _meter.CreateCounter(name: "a-counter-name-param", unit: "cakes-param", description: "cake sales per-capita-param." +#if !NET7_0 + , tags: metricTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateMetricTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Metric(int intParam, bool boolParam) + { + if (_metricInstrument == null) + { + return; + } + + System.Diagnostics.TagList metricTagList = new System.Diagnostics.TagList(); + + metricTagList.Add("intparam", intParam); + metricTagList.Add("boolparam", boolParam); + + _metricInstrument.Add(1, tagList: metricTagList); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_62df27fc09657a48.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..50f1329e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,109 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _metricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary metricTags = new System.Collections.Generic.Dictionary(); + + PopulateMetricTags(metricTags); + +#endif + + _metricInstrument = _meter.CreateCounter(name: "a-counter-name-property", unit: "cakes-property", description: "cake sales per-capita-property." +#if !NET7_0 + , tags: metricTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateMetricTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Metric(int intParam, bool boolParam) + { + if (_metricInstrument == null) + { + return; + } + + System.Diagnostics.TagList metricTagList = new System.Diagnostics.TagList(); + + metricTagList.Add("intparam", intParam); + metricTagList.Add("boolparam", boolParam); + + _metricInstrument.Add(1, tagList: metricTagList); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_67b4564af6cfccb7.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..44796450 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,109 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _metricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary metricTags = new System.Collections.Generic.Dictionary(); + + PopulateMetricTags(metricTags); + +#endif + + _metricInstrument = _meter.CreateCounter(name: "a-counter-name-param", unit: "cakes-param", description: "cake sales per-capita-param." +#if !NET7_0 + , tags: metricTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateMetricTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Metric(int counterValue, int intParam, bool boolParam) + { + if (_metricInstrument == null) + { + return; + } + + System.Diagnostics.TagList metricTagList = new System.Diagnostics.TagList(); + + metricTagList.Add("intparam", intParam); + metricTagList.Add("boolparam", boolParam); + + _metricInstrument.Add(counterValue, tagList: metricTagList); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_7218a9fd161f9f0d.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..842ed045 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,109 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _metricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary metricTags = new System.Collections.Generic.Dictionary(); + + PopulateMetricTags(metricTags); + +#endif + + _metricInstrument = _meter.CreateCounter(name: "a-counter-name-property", unit: "cakes-property", description: "cake sales per-capita-property." +#if !NET7_0 + , tags: metricTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateMetricTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Metric(byte counterValue, int intParam, bool boolParam) + { + if (_metricInstrument == null) + { + return; + } + + System.Diagnostics.TagList metricTagList = new System.Diagnostics.TagList(); + + metricTagList.Add("intparam", intParam); + metricTagList.Add("boolparam", boolParam); + + _metricInstrument.Add(counterValue, tagList: metricTagList); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_8324ee1c4436aaf4.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..45f43a71 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,97 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.ObservableGauge? _metricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Metric(System.Func> f, int intParam, bool boolParam) + { + if (_metricInstrument != null) + { + return; + } + + System.Diagnostics.TagList metricTagList = new System.Diagnostics.TagList(); + + metricTagList.Add("intparam", intParam); + metricTagList.Add("boolparam", boolParam); + + _metricInstrument = _meter.CreateObservableGauge("an-observablegauge-name-property", f, unit: "biscuits-property", description: "biscuit sales per-capita-property." +#if !NET7_0 + , tags: metricTagList +#endif + ); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_857d8d7b899c8174.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..0bce8d80 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,97 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.ObservableUpDownCounter? _metricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Metric(System.Func>> f, int intParam, bool boolParam) + { + if (_metricInstrument != null) + { + return; + } + + System.Diagnostics.TagList metricTagList = new System.Diagnostics.TagList(); + + metricTagList.Add("intparam", intParam); + metricTagList.Add("boolparam", boolParam); + + _metricInstrument = _meter.CreateObservableUpDownCounter("an-observableupdowncounter-name-property", f, unit: "beer-property", description: "beer sales per-capita-property." +#if !NET7_0 + , tags: metricTagList +#endif + ); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_9cbffdbbe83cebed.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..1390e6a9 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,97 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.ObservableGauge? _metricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Metric(System.Func> f, int intParam, bool boolParam) + { + if (_metricInstrument != null) + { + return; + } + + System.Diagnostics.TagList metricTagList = new System.Diagnostics.TagList(); + + metricTagList.Add("intparam", intParam); + metricTagList.Add("boolparam", boolParam); + + _metricInstrument = _meter.CreateObservableGauge("an-observablegauge-name-param", f, unit: "biscuits-param", description: "biscuit ake sales per-capita-param." +#if !NET7_0 + , tags: metricTagList +#endif + ); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_a7399f2a0743c7fd.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..0b2294f8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,97 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.ObservableCounter? _metricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Metric(System.Func f, int intParam, bool boolParam) + { + if (_metricInstrument != null) + { + return; + } + + System.Diagnostics.TagList metricTagList = new System.Diagnostics.TagList(); + + metricTagList.Add("intparam", intParam); + metricTagList.Add("boolparam", boolParam); + + _metricInstrument = _meter.CreateObservableCounter("an-observablecounter-name-param", f, unit: "pie-param", description: "pie sales per-capita-param." +#if !NET7_0 + , tags: metricTagList +#endif + ); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_b202b6b0fcf58c55.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..3f1febd8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,109 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.UpDownCounter? _metricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary metricTags = new System.Collections.Generic.Dictionary(); + + PopulateMetricTags(metricTags); + +#endif + + _metricInstrument = _meter.CreateUpDownCounter(name: "an-updown-counter-name-param", unit: "sponges-param", description: "sponge sales per-capita-param." +#if !NET7_0 + , tags: metricTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateMetricTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Metric(int counterValue, int intParam, bool boolParam) + { + if (_metricInstrument == null) + { + return; + } + + System.Diagnostics.TagList metricTagList = new System.Diagnostics.TagList(); + + metricTagList.Add("intparam", intParam); + metricTagList.Add("boolparam", boolParam); + + _metricInstrument.Add(counterValue, tagList: metricTagList); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_c7ba3499584fbce5.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..496b3ac9 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,97 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.ObservableUpDownCounter? _metricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Metric(System.Func>> f, int intParam, bool boolParam) + { + if (_metricInstrument != null) + { + return; + } + + System.Diagnostics.TagList metricTagList = new System.Diagnostics.TagList(); + + metricTagList.Add("intparam", intParam); + metricTagList.Add("boolparam", boolParam); + + _metricInstrument = _meter.CreateObservableUpDownCounter("an-observableupdowncounter-name-param", f, unit: "beer-param", description: "beer sales per-capita-param." +#if !NET7_0 + , tags: metricTagList +#endif + ); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_f0b7353b0a8a9e52.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..bde41ec9 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,97 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.ObservableCounter? _metricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Metric(System.Func f, int intParam, bool boolParam) + { + if (_metricInstrument != null) + { + return; + } + + System.Diagnostics.TagList metricTagList = new System.Diagnostics.TagList(); + + metricTagList.Add("intparam", intParam); + metricTagList.Add("boolparam", boolParam); + + _metricInstrument = _meter.CreateObservableCounter("an-observablecounter-name-property", f, unit: "pie-property", description: "pie sales per-capita-property." +#if !NET7_0 + , tags: metricTagList +#endif + ); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameUnitsDescription_GeneratesMetrics_fbe9f46d1a4f247e.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..492bf590 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _autoCounterMetricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoCounterMetricTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoCounterMetricTags(autoCounterMetricTags); + +#endif + + _autoCounterMetricInstrument = _meter.CreateCounter(name: "this.is.an.assembly.prefix.this.is.a.prefix.auto-counter", unit: null, description: null +#if !NET7_0 + , tags: autoCounterMetricTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterMetricTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoCounterMetric() + { + if (_autoCounterMetricInstrument == null) + { + return; + } + + _autoCounterMetricInstrument.Add(1, tagList: default); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefixAndName_GeneratesMetricsWithPrefix.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..f5f87090 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _autoCounterMetricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoCounterMetricTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoCounterMetricTags(autoCounterMetricTags); + +#endif + + _autoCounterMetricInstrument = _meter.CreateCounter(name: "this.is.an.assembly.prefix.this.is.a.prefix.autocountermetric", unit: null, description: null +#if !NET7_0 + , tags: autoCounterMetricTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterMetricTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoCounterMetric() + { + if (_autoCounterMetricInstrument == null) + { + return; + } + + _autoCounterMetricInstrument.Add(1, tagList: default); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyAndInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..a16d8d48 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _autoCounterMetricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoCounterMetricTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoCounterMetricTags(autoCounterMetricTags); + +#endif + + _autoCounterMetricInstrument = _meter.CreateCounter(name: "this.is.an.assembly.prefix.autocountermetric", unit: null, description: null +#if !NET7_0 + , tags: autoCounterMetricTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterMetricTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoCounterMetric() + { + if (_autoCounterMetricInstrument == null) + { + return; + } + + _autoCounterMetricInstrument.Add(1, tagList: default); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithAssemblyPrefix_GeneratesMetricsWithPrefix.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..25e27fb1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _autoCounterMetricInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoCounterMetricTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoCounterMetricTags(autoCounterMetricTags); + +#endif + + _autoCounterMetricInstrument = _meter.CreateCounter(name: "this.is.a.prefixautocountermetric", unit: null, description: null +#if !NET7_0 + , tags: autoCounterMetricTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterMetricTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoCounterMetric() + { + if (_autoCounterMetricInstrument == null) + { + return; + } + + _autoCounterMetricInstrument.Add(1, tagList: default); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenNameWithInterfacePrefix_GeneratesMetricsWithPrefix.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..e8a68fc2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,145 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.ObservableCounter? _counterInstrument = null; + System.Diagnostics.Metrics.ObservableGauge? _gaugeInstrument = null; + System.Diagnostics.Metrics.ObservableUpDownCounter? _upDownInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public bool Counter(System.Func counterValue, int intParam, bool boolParam) + { + if (_counterInstrument != null) + { + throw new System.Exception("counter has already been initialized."); + } + + System.Diagnostics.TagList counterTagList = new System.Diagnostics.TagList(); + + counterTagList.Add("intparam", intParam); + counterTagList.Add("boolparam", boolParam); + + _counterInstrument = _meter.CreateObservableCounter("counter", counterValue, unit: null, description: null +#if !NET7_0 + , tags: counterTagList +#endif + ); + + return true; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public bool Gauge(System.Func counterValue, int intParam, bool boolParam) + { + if (_gaugeInstrument != null) + { + throw new System.Exception("gauge has already been initialized."); + } + + System.Diagnostics.TagList gaugeTagList = new System.Diagnostics.TagList(); + + gaugeTagList.Add("intparam", intParam); + gaugeTagList.Add("boolparam", boolParam); + + _gaugeInstrument = _meter.CreateObservableGauge("gauge", counterValue, unit: null, description: null +#if !NET7_0 + , tags: gaugeTagList +#endif + ); + + return true; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public bool UpDown(System.Func counterValue, int intParam, bool boolParam) + { + if (_upDownInstrument != null) + { + throw new System.Exception("updown has already been initialized."); + } + + System.Diagnostics.TagList upDownTagList = new System.Diagnostics.TagList(); + + upDownTagList.Add("intparam", intParam); + upDownTagList.Add("boolparam", boolParam); + + _upDownInstrument = _meter.CreateObservableUpDownCounter("updown", counterValue, unit: null, description: null +#if !NET7_0 + , tags: upDownTagList +#endif + ); + + return true; + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBoolAndThrowsOnAlreadyInitialized_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs new file mode 100644 index 00000000..e77d1b32 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#Testing.TestMetricsCore.Metric.g.verified.cs @@ -0,0 +1,145 @@ +//HintName: Testing.TestMetricsCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestMetricsCore : Testing.ITestMetrics + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.ObservableCounter? _counterInstrument = null; + System.Diagnostics.Metrics.ObservableGauge? _gaugeInstrument = null; + System.Diagnostics.Metrics.ObservableUpDownCounter? _upDownInstrument = null; + + public TestMetricsCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("testing-meter") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "testing-meter", version: null); +#endif + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public bool Counter(System.Func counterValue, int intParam, bool boolParam) + { + if (_counterInstrument != null) + { + return false; + } + + System.Diagnostics.TagList counterTagList = new System.Diagnostics.TagList(); + + counterTagList.Add("intparam", intParam); + counterTagList.Add("boolparam", boolParam); + + _counterInstrument = _meter.CreateObservableCounter("counter", counterValue, unit: null, description: null +#if !NET7_0 + , tags: counterTagList +#endif + ); + + return true; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public bool Gauge(System.Func counterValue, int intParam, bool boolParam) + { + if (_gaugeInstrument != null) + { + return false; + } + + System.Diagnostics.TagList gaugeTagList = new System.Diagnostics.TagList(); + + gaugeTagList.Add("intparam", intParam); + gaugeTagList.Add("boolparam", boolParam); + + _gaugeInstrument = _meter.CreateObservableGauge("gauge", counterValue, unit: null, description: null +#if !NET7_0 + , tags: gaugeTagList +#endif + ); + + return true; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public bool UpDown(System.Func counterValue, int intParam, bool boolParam) + { + if (_upDownInstrument != null) + { + return false; + } + + System.Diagnostics.TagList upDownTagList = new System.Diagnostics.TagList(); + + upDownTagList.Add("intparam", intParam); + upDownTagList.Add("boolparam", boolParam); + + _upDownInstrument = _meter.CreateObservableUpDownCounter("updown", counterValue, unit: null, description: null +#if !NET7_0 + , tags: upDownTagList +#endif + ); + + return true; + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorMetricsTests.Generate_GivenObservablesReturnBool_GeneratesMetrics.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#EntityStoreTelemetryCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#EntityStoreTelemetryCore.Activity.g.verified.cs new file mode 100644 index 00000000..1c7a58fa --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#EntityStoreTelemetryCore.Activity.g.verified.cs @@ -0,0 +1,96 @@ +//HintName: EntityStoreTelemetryCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +sealed partial class EntityStoreTelemetryCore : IEntityStoreTelemetry +{ + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("purview.telemetry.sourcegenerator"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? GettingEntityFromStore(int entityId, string serviceUrl) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityGettingEntityFromStore = _activitySource.StartActivity(name: "GettingEntityFromStore", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityGettingEntityFromStore != null) + { + activityGettingEntityFromStore.SetTag("entityid", entityId); + } + + if (activityGettingEntityFromStore != null) + { + activityGettingEntityFromStore.SetBaggage("serviceurl", serviceUrl); + } + + return activityGettingEntityFromStore; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void GetDuration(System.Diagnostics.Activity? activity, int durationInMS) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionGetDuration = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionGetDuration.Add("durationinms", durationInMS); + + System.Diagnostics.ActivityEvent activityEventGetDuration = new System.Diagnostics.ActivityEvent(name: "GetDuration", timestamp: default, tags: tagsCollectionGetDuration); + + activity.AddEvent(activityEventGetDuration); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void RetrievedEntity(System.Diagnostics.Activity? activity, float totalValue, int lastUpdatedByUserId) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + activity.SetTag("totalvalue", totalValue); + activity.SetTag("lastupdatedbyuserid", lastUpdatedByUserId); + } + } + +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#EntityStoreTelemetryCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#EntityStoreTelemetryCore.Logging.g.verified.cs new file mode 100644 index 00000000..3d5eecd6 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#EntityStoreTelemetryCore.Logging.g.verified.cs @@ -0,0 +1,33 @@ +//HintName: EntityStoreTelemetryCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +sealed partial class EntityStoreTelemetryCore : IEntityStoreTelemetry +{ + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _processingEntityAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "EntityStoreTelemetry.ProcessingEntity: entityId: {EntityId}, updateState: {UpdateState}"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ProcessingEntity(int entityId, string updateState) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _processingEntityAction(_logger, entityId, updateState, null); + } + +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#EntityStoreTelemetryCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#EntityStoreTelemetryCore.Metric.g.verified.cs new file mode 100644 index 00000000..f47be9ea --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#EntityStoreTelemetryCore.Metric.g.verified.cs @@ -0,0 +1,114 @@ +//HintName: EntityStoreTelemetryCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +sealed partial class EntityStoreTelemetryCore : IEntityStoreTelemetry +{ + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _retrievingEntityInstrument = null; + + public EntityStoreTelemetryCore(Microsoft.Extensions.Logging.ILogger logger +#if NET8_0_OR_GREATER +, System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + _logger = logger; + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("EntityStoreTelemetry") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "EntityStoreTelemetry", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary retrievingEntityTags = new System.Collections.Generic.Dictionary(); + + PopulateRetrievingEntityTags(retrievingEntityTags); + +#endif + + _retrievingEntityInstrument = _meter.CreateCounter(name: "retrievingentity", unit: null, description: null +#if !NET7_0 + , tags: retrievingEntityTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateGettingEntityFromStoreTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateGetDurationTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateRetrievedEntityTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateProcessingEntityTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateRetrievingEntityTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void RetrievingEntity(int entityId) + { + if (_retrievingEntityInstrument == null) + { + return; + } + + System.Diagnostics.TagList retrievingEntityTagList = new System.Diagnostics.TagList(); + + retrievingEntityTagList.Add("entityid", entityId); + + _retrievingEntityInstrument.Add(1, tagList: retrievingEntityTagList); + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#EntityStoreTelemetryCoreDIExtension.DependencyInjection.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#EntityStoreTelemetryCoreDIExtension.DependencyInjection.g.verified.cs new file mode 100644 index 00000000..61903197 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#EntityStoreTelemetryCoreDIExtension.DependencyInjection.g.verified.cs @@ -0,0 +1,27 @@ +//HintName: EntityStoreTelemetryCoreDIExtension.DependencyInjection.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Microsoft.Extensions.DependencyInjection +{ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + static class EntityStoreTelemetryCoreDIExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static public Microsoft.Extensions.DependencyInjection.IServiceCollection AddEntityStoreTelemetry(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) + { + return services.AddSingleton(); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromREADMESection_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ActivityTelemetryCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ActivityTelemetryCore.Activity.g.verified.cs new file mode 100644 index 00000000..1574632f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ActivityTelemetryCore.Activity.g.verified.cs @@ -0,0 +1,135 @@ +//HintName: ActivityTelemetryCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +sealed partial class ActivityTelemetryCore : IActivityTelemetry +{ + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("some-activity"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? GettingItemFromCache(string key, string itemType) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityGettingItemFromCache = _activitySource.StartActivity(name: "GettingItemFromCache", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityGettingItemFromCache != null) + { + activityGettingItemFromCache.SetTag("itemtype", itemType); + } + + if (activityGettingItemFromCache != null) + { + activityGettingItemFromCache.SetBaggage("key", key); + } + + return activityGettingItemFromCache; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Miss(System.Diagnostics.Activity? activity) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + + System.Diagnostics.ActivityEvent activityEventMiss = new System.Diagnostics.ActivityEvent(name: "cachemiss", timestamp: default, tags: default); + + activity.AddEvent(activityEventMiss); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Hit(System.Diagnostics.Activity? activity) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + + System.Diagnostics.ActivityEvent activityEventHit = new System.Diagnostics.ActivityEvent(name: "cachehit", timestamp: default, tags: default); + + activity.AddEvent(activityEventHit); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Error(System.Diagnostics.Activity? activity, System.Exception ex) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionError = new System.Diagnostics.ActivityTagsCollection(); + + RecordExceptionInternal(activity: activity, exception: ex, escape: true); + + System.Diagnostics.ActivityEvent activityEventError = new System.Diagnostics.ActivityEvent(name: "Error", timestamp: default, tags: tagsCollectionError); + + activity.AddEvent(activityEventError); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Finished(System.Diagnostics.Activity? activity, System.TimeSpan duration) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionFinished = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionFinished.Add("duration", duration); + + System.Diagnostics.ActivityEvent activityEventFinished = new System.Diagnostics.ActivityEvent(name: "Finished", timestamp: default, tags: tagsCollectionFinished); + + activity.AddEvent(activityEventFinished); + } + } + +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ActivityTelemetryCoreDIExtension.DependencyInjection.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ActivityTelemetryCoreDIExtension.DependencyInjection.g.verified.cs new file mode 100644 index 00000000..6eb466f7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ActivityTelemetryCoreDIExtension.DependencyInjection.g.verified.cs @@ -0,0 +1,27 @@ +//HintName: ActivityTelemetryCoreDIExtension.DependencyInjection.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Microsoft.Extensions.DependencyInjection +{ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + static class ActivityTelemetryCoreDIExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static public Microsoft.Extensions.DependencyInjection.IServiceCollection AddActivityTelemetry(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) + { + return services.AddSingleton(); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiActivitiesSection_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#LoggingTelemetryCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#LoggingTelemetryCore.Logging.g.verified.cs new file mode 100644 index 00000000..8cd6ebce --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#LoggingTelemetryCore.Logging.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: LoggingTelemetryCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +sealed partial class LoggingTelemetryCore : ILoggingTelemetry +{ + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Func _processingWorkItemAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("LoggingTelemetry.ProcessingWorkItem: id: {Id}"); + static readonly System.Action _processingItemTypeAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Trace, default, "LoggingTelemetry.ProcessingItemType: itemType: {ItemType}"); + static readonly System.Action _failedToProcessWorkItemAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Error, default, "LoggingTelemetry.FailedToProcessWorkItem"); + static readonly System.Action _processingCompleteAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "LoggingTelemetry.ProcessingComplete: success: {Success}, duration: {Duration}"); + + public LoggingTelemetryCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? ProcessingWorkItem(System.Guid id) + { + return _processingWorkItemAction(_logger, id); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ProcessingItemType(ItemTypes itemType) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) + { + return; + } + + _processingItemTypeAction(_logger, itemType, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void FailedToProcessWorkItem(System.Exception ex) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) + { + return; + } + + _failedToProcessWorkItemAction(_logger, ex); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ProcessingComplete(bool success, System.TimeSpan duration) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _processingCompleteAction(_logger, success, duration, null); + } + +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#LoggingTelemetryCoreDIExtension.DependencyInjection.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#LoggingTelemetryCoreDIExtension.DependencyInjection.g.verified.cs new file mode 100644 index 00000000..c55be275 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#LoggingTelemetryCoreDIExtension.DependencyInjection.g.verified.cs @@ -0,0 +1,27 @@ +//HintName: LoggingTelemetryCoreDIExtension.DependencyInjection.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Microsoft.Extensions.DependencyInjection +{ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + static class LoggingTelemetryCoreDIExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static public Microsoft.Extensions.DependencyInjection.IServiceCollection AddLoggingTelemetry(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) + { + return services.AddSingleton(); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiLoggingSection_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#MeterTelemetryCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#MeterTelemetryCore.Metric.g.verified.cs new file mode 100644 index 00000000..ab0cb8eb --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#MeterTelemetryCore.Metric.g.verified.cs @@ -0,0 +1,294 @@ +//HintName: MeterTelemetryCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +sealed partial class MeterTelemetryCore : IMeterTelemetry +{ + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _autoCounterMeterInstrument = null; + System.Diagnostics.Metrics.Counter? _autoIncrementMeterInstrument = null; + System.Diagnostics.Metrics.Counter? _counterMeterInstrument = null; + System.Diagnostics.Metrics.Histogram? _histogramMeterInstrument = null; + System.Diagnostics.Metrics.ObservableCounter? _observableCounterMeterInstrument = null; + System.Diagnostics.Metrics.ObservableGauge? _observableGaugeMeterInstrument = null; + System.Diagnostics.Metrics.ObservableUpDownCounter? _observableUpDownCounterInstrument = null; + System.Diagnostics.Metrics.UpDownCounter? _upDownCounterMeterInstrument = null; + + public MeterTelemetryCore( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("MeterTelemetry") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "MeterTelemetry", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoCounterMeterTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoCounterMeterTags(autoCounterMeterTags); + +#endif + + _autoCounterMeterInstrument = _meter.CreateCounter(name: "autocountermeter", unit: null, description: null +#if !NET7_0 + , tags: autoCounterMeterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary autoIncrementMeterTags = new System.Collections.Generic.Dictionary(); + + PopulateAutoIncrementMeterTags(autoIncrementMeterTags); + +#endif + + _autoIncrementMeterInstrument = _meter.CreateCounter(name: "autoincrementmeter", unit: null, description: null +#if !NET7_0 + , tags: autoIncrementMeterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary counterMeterTags = new System.Collections.Generic.Dictionary(); + + PopulateCounterMeterTags(counterMeterTags); + +#endif + + _counterMeterInstrument = _meter.CreateCounter(name: "countermeter", unit: null, description: null +#if !NET7_0 + , tags: counterMeterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary histogramMeterTags = new System.Collections.Generic.Dictionary(); + + PopulateHistogramMeterTags(histogramMeterTags); + +#endif + + _histogramMeterInstrument = _meter.CreateHistogram(name: "histogrammeter", unit: null, description: null +#if !NET7_0 + , tags: histogramMeterTags +#endif + ); + +#if !NET7_0 + + System.Collections.Generic.Dictionary upDownCounterMeterTags = new System.Collections.Generic.Dictionary(); + + PopulateUpDownCounterMeterTags(upDownCounterMeterTags); + +#endif + + _upDownCounterMeterInstrument = _meter.CreateUpDownCounter(name: "updowncountermeter", unit: null, description: null +#if !NET7_0 + , tags: upDownCounterMeterTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateAutoCounterMeterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateAutoIncrementMeterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounterMeterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateHistogramMeterTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateUpDownCounterMeterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoCounterMeter(string someValue) + { + if (_autoCounterMeterInstrument == null) + { + return; + } + + System.Diagnostics.TagList autoCounterMeterTagList = new System.Diagnostics.TagList(); + + autoCounterMeterTagList.Add("somevalue", someValue); + + _autoCounterMeterInstrument.Add(1, tagList: autoCounterMeterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AutoIncrementMeter(string someValue) + { + if (_autoIncrementMeterInstrument == null) + { + return; + } + + System.Diagnostics.TagList autoIncrementMeterTagList = new System.Diagnostics.TagList(); + + autoIncrementMeterTagList.Add("somevalue", someValue); + + _autoIncrementMeterInstrument.Add(1, tagList: autoIncrementMeterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void CounterMeter(int measurement, float someValue) + { + if (_counterMeterInstrument == null) + { + return; + } + + System.Diagnostics.TagList counterMeterTagList = new System.Diagnostics.TagList(); + + counterMeterTagList.Add("somevalue", someValue); + + _counterMeterInstrument.Add(measurement, tagList: counterMeterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void HistogramMeter(int measurement, int someValue, bool anotherValue) + { + if (_histogramMeterInstrument == null) + { + return; + } + + System.Diagnostics.TagList histogramMeterTagList = new System.Diagnostics.TagList(); + + histogramMeterTagList.Add("somevalue", someValue); + histogramMeterTagList.Add("anothervalue", anotherValue); + + _histogramMeterInstrument.Record(measurement, tagList: histogramMeterTagList); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableCounterMeter(System.Func measurement, double someValue) + { + if (_observableCounterMeterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableCounterMeterTagList = new System.Diagnostics.TagList(); + + observableCounterMeterTagList.Add("somevalue", someValue); + + _observableCounterMeterInstrument = _meter.CreateObservableCounter("observablecountermeter", measurement, unit: null, description: null +#if !NET7_0 + , tags: observableCounterMeterTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableGaugeMeter(System.Func> measurement, double someValue) + { + if (_observableGaugeMeterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableGaugeMeterTagList = new System.Diagnostics.TagList(); + + observableGaugeMeterTagList.Add("somevalue", someValue); + + _observableGaugeMeterInstrument = _meter.CreateObservableGauge("observablegaugemeter", measurement, unit: null, description: null +#if !NET7_0 + , tags: observableGaugeMeterTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ObservableUpDownCounter(System.Func>> measurement, double someValue) + { + if (_observableUpDownCounterInstrument != null) + { + return; + } + + System.Diagnostics.TagList observableUpDownCounterTagList = new System.Diagnostics.TagList(); + + observableUpDownCounterTagList.Add("somevalue", someValue); + + _observableUpDownCounterInstrument = _meter.CreateObservableUpDownCounter("observableupdowncounter", measurement, unit: null, description: null +#if !NET7_0 + , tags: observableUpDownCounterTagList +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void UpDownCounterMeter(decimal measurement, byte someValue) + { + if (_upDownCounterMeterInstrument == null) + { + return; + } + + System.Diagnostics.TagList upDownCounterMeterTagList = new System.Diagnostics.TagList(); + + upDownCounterMeterTagList.Add("somevalue", someValue); + + _upDownCounterMeterInstrument.Add(measurement, tagList: upDownCounterMeterTagList); + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#MeterTelemetryCoreDIExtension.DependencyInjection.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#MeterTelemetryCoreDIExtension.DependencyInjection.g.verified.cs new file mode 100644 index 00000000..2eaaaa85 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#MeterTelemetryCoreDIExtension.DependencyInjection.g.verified.cs @@ -0,0 +1,27 @@ +//HintName: MeterTelemetryCoreDIExtension.DependencyInjection.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Microsoft.Extensions.DependencyInjection +{ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + static class MeterTelemetryCoreDIExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static public Microsoft.Extensions.DependencyInjection.IServiceCollection AddMeterTelemetry(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) + { + return services.AddSingleton(); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMetricsSection_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ServiceTelemetryCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ServiceTelemetryCore.Activity.g.verified.cs new file mode 100644 index 00000000..0320320f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ServiceTelemetryCore.Activity.g.verified.cs @@ -0,0 +1,96 @@ +//HintName: ServiceTelemetryCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +sealed partial class ServiceTelemetryCore : IServiceTelemetry +{ + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("multi-targetting"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? StartAnActivity(int tagIntParam, string entityId) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityStartAnActivity = _activitySource.StartActivity(name: "StartAnActivity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityStartAnActivity != null) + { + activityStartAnActivity.SetTag("tagintparam", tagIntParam); + } + + if (activityStartAnActivity != null) + { + activityStartAnActivity.SetBaggage("entityid", entityId); + } + + return activityStartAnActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AnInterestingEvent(System.Diagnostics.Activity? activity, float aTagValue) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionAnInterestingEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionAnInterestingEvent.Add("atagvalue", aTagValue); + + System.Diagnostics.ActivityEvent activityEventAnInterestingEvent = new System.Diagnostics.ActivityEvent(name: "AnInterestingEvent", timestamp: default, tags: tagsCollectionAnInterestingEvent); + + activity.AddEvent(activityEventAnInterestingEvent); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void InterestingInfo(System.Diagnostics.Activity? activity, float anotherTagValue, int intTagValue) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + activity.SetTag("anothertagvalue", anotherTagValue); + activity.SetTag("inttagvalue", intTagValue); + } + } + +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ServiceTelemetryCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ServiceTelemetryCore.Logging.g.verified.cs new file mode 100644 index 00000000..e7fe618d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ServiceTelemetryCore.Logging.g.verified.cs @@ -0,0 +1,33 @@ +//HintName: ServiceTelemetryCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +sealed partial class ServiceTelemetryCore : IServiceTelemetry +{ + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _processingEntityAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "ServiceTelemetry.ProcessingEntity: entityId: {EntityId}, property1: {Property1}"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ProcessingEntity(int entityId, string property1) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _processingEntityAction(_logger, entityId, property1, null); + } + +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ServiceTelemetryCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ServiceTelemetryCore.Metric.g.verified.cs new file mode 100644 index 00000000..8092bb70 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ServiceTelemetryCore.Metric.g.verified.cs @@ -0,0 +1,114 @@ +//HintName: ServiceTelemetryCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +sealed partial class ServiceTelemetryCore : IServiceTelemetry +{ + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _anAutoIncrementInstrument = null; + + public ServiceTelemetryCore(Microsoft.Extensions.Logging.ILogger logger +#if NET8_0_OR_GREATER +, System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + _logger = logger; + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("ServiceTelemetry") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "ServiceTelemetry", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary anAutoIncrementTags = new System.Collections.Generic.Dictionary(); + + PopulateAnAutoIncrementTags(anAutoIncrementTags); + +#endif + + _anAutoIncrementInstrument = _meter.CreateCounter(name: "anautoincrement", unit: null, description: null +#if !NET7_0 + , tags: anAutoIncrementTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateStartAnActivityTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateAnInterestingEventTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateInterestingInfoTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateProcessingEntityTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateAnAutoIncrementTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void AnAutoIncrement(int value) + { + if (_anAutoIncrementInstrument == null) + { + return; + } + + System.Diagnostics.TagList anAutoIncrementTagList = new System.Diagnostics.TagList(); + + anAutoIncrementTagList.Add("value", value); + + _anAutoIncrementInstrument.Add(1, tagList: anAutoIncrementTagList); + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ServiceTelemetryCoreDIExtension.DependencyInjection.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ServiceTelemetryCoreDIExtension.DependencyInjection.g.verified.cs new file mode 100644 index 00000000..62f7e887 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#ServiceTelemetryCoreDIExtension.DependencyInjection.g.verified.cs @@ -0,0 +1,27 @@ +//HintName: ServiceTelemetryCoreDIExtension.DependencyInjection.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Microsoft.Extensions.DependencyInjection +{ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + static class ServiceTelemetryCoreDIExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static public Microsoft.Extensions.DependencyInjection.IServiceCollection AddServiceTelemetry(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) + { + return services.AddSingleton(); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_FromWikiMultiTargetingSection_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs new file mode 100644 index 00000000..04433d2e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: Testing.TestTelemetryCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestTelemetryCore : Testing.ITestTelemetry + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void EventMethod(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam, System.Exception anException, bool escape) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEventMethod = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEventMethod.Add("intparam", intParam); + tagsCollectionEventMethod.Add("boolparam", boolParam); + tagsCollectionEventMethod.Add("anexception", anException.ToString()); + + System.Diagnostics.ActivityEvent activityEventEventMethod = new System.Diagnostics.ActivityEvent(name: "EventMethod", timestamp: default, tags: tagsCollectionEventMethod); + + activity.AddEvent(activityEventEventMethod); + + activity.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs new file mode 100644 index 00000000..0cf57be1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs @@ -0,0 +1,79 @@ +//HintName: Testing.TestTelemetryCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestTelemetryCore : Testing.ITestTelemetry + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam, System.Exception anException, bool escape) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("intparam", intParam); + tagsCollectionEvent.Add("boolparam", boolParam); + + RecordExceptionInternal(activity: activity, exception: anException, escape: escape); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + + activity.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs new file mode 100644 index 00000000..83453632 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs @@ -0,0 +1,79 @@ +//HintName: Testing.TestTelemetryCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestTelemetryCore : Testing.ITestTelemetry + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam, System.Exception anException) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("intparam", intParam); + tagsCollectionEvent.Add("boolparam", boolParam); + + RecordExceptionInternal(activity: activity, exception: anException, escape: true); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + + activity.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs new file mode 100644 index 00000000..a65f9ef5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: Testing.TestTelemetryCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestTelemetryCore : Testing.ITestTelemetry + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void EventMethod(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam, System.Exception anException, bool escape) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEventMethod = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEventMethod.Add("intparam", intParam); + tagsCollectionEventMethod.Add("boolparam", boolParam); + if (anException != null) + { + tagsCollectionEventMethod.Add("exception.escaped", escape); + tagsCollectionEventMethod.Add("exception.message", anException.Message); + tagsCollectionEventMethod.Add("exception.type", anException.GetType().FullName); + tagsCollectionEventMethod.Add("exception.stacktrace", anException.StackTrace); + } + + System.Diagnostics.ActivityEvent activityEventEventMethod = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollectionEventMethod); + + activity.AddEvent(activityEventEventMethod); + + activity.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs new file mode 100644 index 00000000..a65f9ef5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: Testing.TestTelemetryCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestTelemetryCore : Testing.ITestTelemetry + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void EventMethod(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam, System.Exception anException, bool escape) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEventMethod = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEventMethod.Add("intparam", intParam); + tagsCollectionEventMethod.Add("boolparam", boolParam); + if (anException != null) + { + tagsCollectionEventMethod.Add("exception.escaped", escape); + tagsCollectionEventMethod.Add("exception.message", anException.Message); + tagsCollectionEventMethod.Add("exception.type", anException.GetType().FullName); + tagsCollectionEventMethod.Add("exception.stacktrace", anException.StackTrace); + } + + System.Diagnostics.ActivityEvent activityEventEventMethod = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollectionEventMethod); + + activity.AddEvent(activityEventEventMethod); + + activity.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs new file mode 100644 index 00000000..9e17e9b3 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: Testing.TestTelemetryCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestTelemetryCore : Testing.ITestTelemetry + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity(string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("intparam", intParam); + activityActivity.SetTag("boolparam", boolParam); + } + + if (activityActivity != null) + { + activityActivity.SetBaggage("stringparam", stringParam); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("intparam", intParam); + tagsCollectionEvent.Add("boolparam", boolParam); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + + activity.SetBaggage("stringparam", stringParam); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Context(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + activity.SetTag("intparam", intParam); + activity.SetTag("boolparam", boolParam); + activity.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Logging.g.verified.cs new file mode 100644 index 00000000..ef174a95 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Logging.g.verified.cs @@ -0,0 +1,44 @@ +//HintName: Testing.TestTelemetryCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestTelemetryCore : Testing.ITestTelemetry + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "TestTelemetry.Log: intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Func _logScopeAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("TestTelemetry.LogScope: intParam: {IntParam}, boolParam: {BoolParam}"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? LogScope(int intParam, bool boolParam) + { + return _logScopeAction(_logger, intParam, boolParam); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Metric.g.verified.cs new file mode 100644 index 00000000..f5923e53 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#Testing.TestTelemetryCore.Metric.g.verified.cs @@ -0,0 +1,122 @@ +//HintName: Testing.TestTelemetryCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestTelemetryCore : Testing.ITestTelemetry + { + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _counterInstrument = null; + + public TestTelemetryCore(Microsoft.Extensions.Logging.ILogger logger +#if NET8_0_OR_GREATER +, System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + _logger = logger; + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("TestTelemetry") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "TestTelemetry", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary counterTags = new System.Collections.Generic.Dictionary(); + + PopulateCounterTags(counterTags); + +#endif + + _counterInstrument = _meter.CreateCounter(name: "counter", unit: null, description: null +#if !NET7_0 + , tags: counterTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateActivityTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateEventTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateContextTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateLogTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateLogScopeTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public bool Counter(int counterValue, int intParam, bool boolParam) + { + if (_counterInstrument == null) + { + return false; + } + + System.Diagnostics.TagList counterTagList = new System.Diagnostics.TagList(); + + counterTagList.Add("intparam", intParam); + counterTagList.Add("boolparam", boolParam); + + _counterInstrument.Add(counterValue, tagList: counterTagList); + + return true; + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicTelemetryGen_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0.verified.txt b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0.verified.txt new file mode 100644 index 00000000..9280482f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityEventContextMethodNames_GeneratesDiagnostic.DotNet9_0.verified.txt @@ -0,0 +1,23 @@ +{ + Diagnostics: [ + { + Location: /* + [Activity] + System.Diagnostics.Activity? DuplicateMethodName([Baggage]string stringParam, [Tag]int intParam, bool boolParam); + ^^^^^^^^^^^^^^^^^^^ + +*/ + Guid_1: (11,30)-(11,49), + Message: Two or more methods named 'DuplicateMethodName' are defined. Keep method names unique as they're used to generate other members on the implementation class., + Severity: Error, + Descriptor: { + Id: TSG1003, + Title: Duplicate method names are not supported, + MessageFormat: Two or more methods named '{0}' are defined. Keep method names unique as they're used to generate other members on the implementation class., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + } + ] +} \ No newline at end of file diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0.verified.txt b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0.verified.txt new file mode 100644 index 00000000..9280482f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateActivityMethodNames_GeneratesDiagnostic.DotNet9_0.verified.txt @@ -0,0 +1,23 @@ +{ + Diagnostics: [ + { + Location: /* + [Activity] + System.Diagnostics.Activity? DuplicateMethodName([Baggage]string stringParam, [Tag]int intParam, bool boolParam); + ^^^^^^^^^^^^^^^^^^^ + +*/ + Guid_1: (11,30)-(11,49), + Message: Two or more methods named 'DuplicateMethodName' are defined. Keep method names unique as they're used to generate other members on the implementation class., + Severity: Error, + Descriptor: { + Id: TSG1003, + Title: Duplicate method names are not supported, + MessageFormat: Two or more methods named '{0}' are defined. Keep method names unique as they're used to generate other members on the implementation class., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + } + ] +} \ No newline at end of file diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0.verified.txt b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0.verified.txt new file mode 100644 index 00000000..a0738091 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateLoggingMethodNames_GeneratesDiagnostic.DotNet9_0.verified.txt @@ -0,0 +1,23 @@ +{ + Diagnostics: [ + { + Location: /* + [Log] + IDisposable? DuplicateMethodName(string stringParam, int intParam, bool boolParam); + ^^^^^^^^^^^^^^^^^^^ + +*/ + Guid_1: (11,14)-(11,33), + Message: Two or more methods named 'DuplicateMethodName' are defined. Keep method names unique as they're used to generate other members on the implementation class., + Severity: Error, + Descriptor: { + Id: TSG1003, + Title: Duplicate method names are not supported, + MessageFormat: Two or more methods named '{0}' are defined. Keep method names unique as they're used to generate other members on the implementation class., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + } + ] +} \ No newline at end of file diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0.verified.txt b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0.verified.txt new file mode 100644 index 00000000..27d45fcf --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMetricsMethodNames_GeneratesDiagnostic.DotNet9_0.verified.txt @@ -0,0 +1,23 @@ +{ + Diagnostics: [ + { + Location: /* + [AutoCounter] + void DuplicateMethodName(string stringParam, int intParam, bool boolParam); + ^^^^^^^^^^^^^^^^^^^ + +*/ + Guid_1: (11,6)-(11,25), + Message: Two or more methods named 'DuplicateMethodName' are defined. Keep method names unique as they're used to generate other members on the implementation class., + Severity: Error, + Descriptor: { + Id: TSG1003, + Title: Duplicate method names are not supported, + MessageFormat: Two or more methods named '{0}' are defined. Keep method names unique as they're used to generate other members on the implementation class., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + } + ] +} \ No newline at end of file diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0.verified.txt b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0.verified.txt new file mode 100644 index 00000000..8d4c728f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateMultiTargetMethodNames_GeneratesDiagnostic.DotNet9_0.verified.txt @@ -0,0 +1,23 @@ +{ + Diagnostics: [ + { + Location: /* + [Activity] + System.Diagnostics.Activity? DuplicateMethodName([Baggage]string stringParam, [Tag]int intParam, bool boolParam); + ^^^^^^^^^^^^^^^^^^^ + +*/ + Guid_1: (15,30)-(15,49), + Message: Two or more methods named 'DuplicateMethodName' are defined. Keep method names unique as they're used to generate other members on the implementation class., + Severity: Error, + Descriptor: { + Id: TSG1003, + Title: Duplicate method names are not supported, + MessageFormat: Two or more methods named '{0}' are defined. Keep method names unique as they're used to generate other members on the implementation class., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + } + ] +} \ No newline at end of file diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs new file mode 100644 index 00000000..662fd051 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#Testing.TestTelemetryCore.Activity.g.verified.cs @@ -0,0 +1,42 @@ +//HintName: Testing.TestTelemetryCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestTelemetryCore : Testing.ITestTelemetry + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#Testing.TestTelemetryCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#Testing.TestTelemetryCore.Logging.g.verified.cs new file mode 100644 index 00000000..67bdc961 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#Testing.TestTelemetryCore.Logging.g.verified.cs @@ -0,0 +1,23 @@ +//HintName: Testing.TestTelemetryCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestTelemetryCore : Testing.ITestTelemetry + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#Testing.TestTelemetryCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#Testing.TestTelemetryCore.Metric.g.verified.cs new file mode 100644 index 00000000..d084f3c1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#Testing.TestTelemetryCore.Metric.g.verified.cs @@ -0,0 +1,89 @@ +//HintName: Testing.TestTelemetryCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestTelemetryCore : Testing.ITestTelemetry + { + System.Diagnostics.Metrics.Meter _meter = default!; + + + public TestTelemetryCore(Microsoft.Extensions.Logging.ILogger logger +#if NET8_0_OR_GREATER +, System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + _logger = logger; + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("TestTelemetry") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "TestTelemetry", version: null); +#endif + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateActivityTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateEventTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateContextTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateLogTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateLogScopeTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0.verified.txt b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0.verified.txt new file mode 100644 index 00000000..0e1a86a0 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenDuplicateTelemetryGen_GeneratesDiagnostics.DotNet9_0.verified.txt @@ -0,0 +1,346 @@ +{ + Diagnostics: [ + { + Location: /* + [Log] + void Activity([Baggage]string stringParam, [Tag]int intParam, bool boolParam); + ^^^^^^^^ + +*/ + Guid_1: (18,6)-(18,14), + Message: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Severity: Error, + Descriptor: { + Id: TSG1002, + Title: Multiple generation types are not supported, + MessageFormat: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Counter] + void Event([Baggage]string stringParam, [Tag]int intParam, bool boolParam); + ^^^^^ + +*/ + Guid_1: (22,6)-(22,11), + Message: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Severity: Error, + Descriptor: { + Id: TSG1002, + Title: Multiple generation types are not supported, + MessageFormat: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Activity] + void Context([Baggage]string stringParam, [Tag]int intParam, bool boolParam); + ^^^^^^^ + +*/ + Guid_1: (26,6)-(26,13), + Message: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Severity: Error, + Descriptor: { + Id: TSG1002, + Title: Multiple generation types are not supported, + MessageFormat: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Counter] + void Log([Tag]int intParam, bool boolParam); + ^^^ + +*/ + Guid_1: (30,6)-(30,9), + Message: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Severity: Error, + Descriptor: { + Id: TSG1002, + Title: Multiple generation types are not supported, + MessageFormat: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Activity] + IDisposable? LogScope([Tag]int intParam, bool boolParam); + ^^^^^^^^ + +*/ + Guid_1: (34,14)-(34,22), + Message: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Severity: Error, + Descriptor: { + Id: TSG1002, + Title: Multiple generation types are not supported, + MessageFormat: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Log] + void Counter(int counterValue, [Tag]int intParam, bool boolParam); + ^^^^^^^ +} +*/ + Guid_1: (39,6)-(39,13), + Message: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Severity: Error, + Descriptor: { + Id: TSG1002, + Title: Multiple generation types are not supported, + MessageFormat: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Log] + void Activity([Baggage]string stringParam, [Tag]int intParam, bool boolParam); + ^^^^^^^^ + +*/ + Guid_1: (18,6)-(18,14), + Message: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Severity: Error, + Descriptor: { + Id: TSG1002, + Title: Multiple generation types are not supported, + MessageFormat: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Counter] + void Event([Baggage]string stringParam, [Tag]int intParam, bool boolParam); + ^^^^^ + +*/ + Guid_1: (22,6)-(22,11), + Message: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Severity: Error, + Descriptor: { + Id: TSG1002, + Title: Multiple generation types are not supported, + MessageFormat: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Activity] + void Context([Baggage]string stringParam, [Tag]int intParam, bool boolParam); + ^^^^^^^ + +*/ + Guid_1: (26,6)-(26,13), + Message: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Severity: Error, + Descriptor: { + Id: TSG1002, + Title: Multiple generation types are not supported, + MessageFormat: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Counter] + void Log([Tag]int intParam, bool boolParam); + ^^^ + +*/ + Guid_1: (30,6)-(30,9), + Message: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Severity: Error, + Descriptor: { + Id: TSG1002, + Title: Multiple generation types are not supported, + MessageFormat: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Activity] + IDisposable? LogScope([Tag]int intParam, bool boolParam); + ^^^^^^^^ + +*/ + Guid_1: (34,14)-(34,22), + Message: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Severity: Error, + Descriptor: { + Id: TSG1002, + Title: Multiple generation types are not supported, + MessageFormat: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Log] + void Counter(int counterValue, [Tag]int intParam, bool boolParam); + ^^^^^^^ +} +*/ + Guid_1: (39,6)-(39,13), + Message: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Severity: Error, + Descriptor: { + Id: TSG1002, + Title: Multiple generation types are not supported, + MessageFormat: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Log] + void Activity([Baggage]string stringParam, [Tag]int intParam, bool boolParam); + ^^^^^^^^ + +*/ + Guid_1: (18,6)-(18,14), + Message: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Severity: Error, + Descriptor: { + Id: TSG1002, + Title: Multiple generation types are not supported, + MessageFormat: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Counter] + void Event([Baggage]string stringParam, [Tag]int intParam, bool boolParam); + ^^^^^ + +*/ + Guid_1: (22,6)-(22,11), + Message: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Severity: Error, + Descriptor: { + Id: TSG1002, + Title: Multiple generation types are not supported, + MessageFormat: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Activity] + void Context([Baggage]string stringParam, [Tag]int intParam, bool boolParam); + ^^^^^^^ + +*/ + Guid_1: (26,6)-(26,13), + Message: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Severity: Error, + Descriptor: { + Id: TSG1002, + Title: Multiple generation types are not supported, + MessageFormat: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Counter] + void Log([Tag]int intParam, bool boolParam); + ^^^ + +*/ + Guid_1: (30,6)-(30,9), + Message: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Severity: Error, + Descriptor: { + Id: TSG1002, + Title: Multiple generation types are not supported, + MessageFormat: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Activity] + IDisposable? LogScope([Tag]int intParam, bool boolParam); + ^^^^^^^^ + +*/ + Guid_1: (34,14)-(34,22), + Message: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Severity: Error, + Descriptor: { + Id: TSG1002, + Title: Multiple generation types are not supported, + MessageFormat: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Log] + void Counter(int counterValue, [Tag]int intParam, bool boolParam); + ^^^^^^^ +} +*/ + Guid_1: (39,6)-(39,13), + Message: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Severity: Error, + Descriptor: { + Id: TSG1002, + Title: Multiple generation types are not supported, + MessageFormat: Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: ActivityAttribute, EventAttribute, ContextAttribute, LogAttribute, WarningAttribute, CounterAttribute, HistogramAttribute, UpDownCounterAttribute, ObservableCounterAttribute, ObservableGaugeAttribute or ObservableUpDownCounterAttribute., + Category: Usage, + DefaultSeverity: Error, + IsEnabledByDefault: true + } + } + ] +} \ No newline at end of file diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenGeneratedAttributes_GeneratesAsExpected.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#Purview.Interfaces.ApplicationServices.Caching.CacheServiceProviderTelemetryCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#Purview.Interfaces.ApplicationServices.Caching.CacheServiceProviderTelemetryCore.Activity.g.verified.cs new file mode 100644 index 00000000..0306344d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#Purview.Interfaces.ApplicationServices.Caching.CacheServiceProviderTelemetryCore.Activity.g.verified.cs @@ -0,0 +1,237 @@ +//HintName: Purview.Interfaces.ApplicationServices.Caching.CacheServiceProviderTelemetryCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Interfaces.ApplicationServices.Caching +{ + sealed partial class CacheServiceProviderTelemetryCore : Purview.Interfaces.ApplicationServices.Caching.ICacheServiceProviderTelemetry + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("purview.telemetry.sourcegenerator"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? GetFromCache() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityGetFromCache = _activitySource.StartActivity(name: "GetFromCache", kind: System.Diagnostics.ActivityKind.Client, parentId: default, tags: default, links: default, startTime: default); + + return activityGetFromCache; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void NoValueProvided() + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (System.Diagnostics.Activity.Current != null) + { + + System.Diagnostics.ActivityEvent activityEventNoValueProvided = new System.Diagnostics.ActivityEvent(name: "NoValueProvided", timestamp: default, tags: default); + + System.Diagnostics.Activity.Current.AddEvent(activityEventNoValueProvided); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? SerializePayload() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activitySerializePayload = _activitySource.StartActivity(name: "SerializePayload", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activitySerializePayload; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void SerializePayloadResult(int payloadStringLength) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (System.Diagnostics.Activity.Current != null) + { + System.Diagnostics.Activity.Current.SetTag("payloadstringlength", payloadStringLength); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? SetInCache() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activitySetInCache = _activitySource.StartActivity(name: "SetInCache", kind: System.Diagnostics.ActivityKind.Client, parentId: default, tags: default, links: default, startTime: default); + + return activitySetInCache; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void SetDefaultTags(string distributedCacheType, string cacheKey, string? entityType) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (System.Diagnostics.Activity.Current != null) + { + System.Diagnostics.Activity.Current.SetTag("distributedcachetype", distributedCacheType); + System.Diagnostics.Activity.Current.SetTag("cachekey", cacheKey); + System.Diagnostics.Activity.Current.SetTag("entitytype", entityType); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void ValueCached() + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (System.Diagnostics.Activity.Current != null) + { + + System.Diagnostics.ActivityEvent activityEventValueCached = new System.Diagnostics.ActivityEvent(name: "ValueCached", timestamp: default, tags: default); + + System.Diagnostics.Activity.Current.AddEvent(activityEventValueCached); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void RequestingValueFromCache() + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (System.Diagnostics.Activity.Current != null) + { + + System.Diagnostics.ActivityEvent activityEventRequestingValueFromCache = new System.Diagnostics.ActivityEvent(name: "RequestingValueFromCache", timestamp: default, tags: default); + + System.Diagnostics.Activity.Current.AddEvent(activityEventRequestingValueFromCache); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void CacheHit(int? dataLength) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (System.Diagnostics.Activity.Current != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionCacheHit = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionCacheHit.Add("datalength", dataLength); + + System.Diagnostics.ActivityEvent activityEventCacheHit = new System.Diagnostics.ActivityEvent(name: "CacheHit", timestamp: default, tags: tagsCollectionCacheHit); + + System.Diagnostics.Activity.Current.AddEvent(activityEventCacheHit); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void CacheMiss() + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (System.Diagnostics.Activity.Current != null) + { + + System.Diagnostics.ActivityEvent activityEventCacheMiss = new System.Diagnostics.ActivityEvent(name: "CacheMiss", timestamp: default, tags: default); + + System.Diagnostics.Activity.Current.AddEvent(activityEventCacheMiss); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? DeserializePayload() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityDeserializePayload = _activitySource.StartActivity(name: "DeserializePayload", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + return activityDeserializePayload; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Refresh() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityRefresh = _activitySource.StartActivity(name: "Refresh", kind: System.Diagnostics.ActivityKind.Client, parentId: default, tags: default, links: default, startTime: default); + + return activityRefresh; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Remove() + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityRemove = _activitySource.StartActivity(name: "Remove", kind: System.Diagnostics.ActivityKind.Client, parentId: default, tags: default, links: default, startTime: default); + + return activityRemove; + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#Purview.Interfaces.ApplicationServices.Caching.CacheServiceProviderTelemetryCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#Purview.Interfaces.ApplicationServices.Caching.CacheServiceProviderTelemetryCore.Logging.g.verified.cs new file mode 100644 index 00000000..9545655b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#Purview.Interfaces.ApplicationServices.Caching.CacheServiceProviderTelemetryCore.Logging.g.verified.cs @@ -0,0 +1,119 @@ +//HintName: Purview.Interfaces.ApplicationServices.Caching.CacheServiceProviderTelemetryCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Interfaces.ApplicationServices.Caching +{ + sealed partial class CacheServiceProviderTelemetryCore : Purview.Interfaces.ApplicationServices.Caching.ICacheServiceProviderTelemetry + { + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _failedToDeserializePayloadAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "CacheServiceProviderTelemetry.FailedToDeserializePayload: dataLength: {DataLength}"); + static readonly System.Action _failedToGetFromCacheAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "CacheServiceProviderTelemetry.FailedToGetFromCache: key: {Key}"); + static readonly System.Action _failedToRefreshAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "CacheServiceProviderTelemetry.FailedToRefresh: cacheKey: {CacheKey}"); + static readonly System.Action _failedToRemoveAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "CacheServiceProviderTelemetry.FailedToRemove: key: {Key}"); + static readonly System.Action _failedToSerializePayloadAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "CacheServiceProviderTelemetry.FailedToSerializePayload: fullName: {FullName}"); + static readonly System.Action _failedToSetValueInCacheAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "CacheServiceProviderTelemetry.FailedToSetValueInCache: key: {Key}"); + static readonly System.Action _usingDistributedCacheAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "CacheServiceProviderTelemetry.UsingDistributedCache: fullName: {FullName}, isNullCache: {IsNullCache}"); + + public CacheServiceProviderTelemetryCore(Microsoft.Extensions.Logging.ILogger logger) + { + _logger = logger; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void FailedToDeserializePayload(int dataLength, System.Exception ex) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _failedToDeserializePayloadAction(_logger, dataLength, ex); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void FailedToGetFromCache(string key, System.Exception ex) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _failedToGetFromCacheAction(_logger, key, ex); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void FailedToRefresh(string cacheKey, System.Exception ex) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _failedToRefreshAction(_logger, cacheKey, ex); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void FailedToRemove(string key, System.Exception ex) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _failedToRemoveAction(_logger, key, ex); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void FailedToSerializePayload(string? fullName, System.Exception ex) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _failedToSerializePayloadAction(_logger, fullName, ex); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void FailedToSetValueInCache(string key, System.Exception ex) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _failedToSetValueInCacheAction(_logger, key, ex); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void UsingDistributedCache(string? fullName, bool isNullCache) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _usingDistributedCacheAction(_logger, fullName, isNullCache, null); + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#Purview.Interfaces.ApplicationServices.Caching.CacheServiceProviderTelemetryCoreDIExtension.DependencyInjection.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#Purview.Interfaces.ApplicationServices.Caching.CacheServiceProviderTelemetryCoreDIExtension.DependencyInjection.g.verified.cs new file mode 100644 index 00000000..509cd2bd --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#Purview.Interfaces.ApplicationServices.Caching.CacheServiceProviderTelemetryCoreDIExtension.DependencyInjection.g.verified.cs @@ -0,0 +1,27 @@ +//HintName: Purview.Interfaces.ApplicationServices.Caching.CacheServiceProviderTelemetryCoreDIExtension.DependencyInjection.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Microsoft.Extensions.DependencyInjection +{ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + static class CacheServiceProviderTelemetryCoreDIExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static public Microsoft.Extensions.DependencyInjection.IServiceCollection AddCacheServiceProviderTelemetry(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) + { + return services.AddSingleton(); + } + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0.verified.txt b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0.verified.txt new file mode 100644 index 00000000..1383937d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenICacheServiceProviderTelemetry_GeneratesTelemetry.DotNet9_0.verified.txt @@ -0,0 +1,144 @@ +{ + Diagnostics: [ + { + Location: /* + [Event] + void NoValueProvided(); + ^^^^^^^^^^^^^^^ + +*/ + Guid_1: (41,6)-(41,21), + Message: It's best practice to accept an Activity parameter to ensure the Event, Tags and/ or Baggage are applied to the Activity you intended., + Severity: Warning, + WarningLevel: 1, + Descriptor: { + Id: TSG3014, + Title: Should accept an Activity to apply the Event/ Tags/ Baggage too, + MessageFormat: It's best practice to accept an Activity parameter to ensure the Event, Tags and/ or Baggage are applied to the Activity you intended., + Category: Activity.Usage, + DefaultSeverity: Warning, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Context] + void SerializePayloadResult(int payloadStringLength); + ^^^^^^^^^^^^^^^^^^^^^^ + +*/ + Guid_1: (47,6)-(47,28), + Message: It's best practice to accept an Activity parameter to ensure the Event, Tags and/ or Baggage are applied to the Activity you intended., + Severity: Warning, + WarningLevel: 1, + Descriptor: { + Id: TSG3014, + Title: Should accept an Activity to apply the Event/ Tags/ Baggage too, + MessageFormat: It's best practice to accept an Activity parameter to ensure the Event, Tags and/ or Baggage are applied to the Activity you intended., + Category: Activity.Usage, + DefaultSeverity: Warning, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Context] + void SetDefaultTags(string distributedCacheType, string cacheKey, string? entityType); + ^^^^^^^^^^^^^^ + +*/ + Guid_1: (53,6)-(53,20), + Message: It's best practice to accept an Activity parameter to ensure the Event, Tags and/ or Baggage are applied to the Activity you intended., + Severity: Warning, + WarningLevel: 1, + Descriptor: { + Id: TSG3014, + Title: Should accept an Activity to apply the Event/ Tags/ Baggage too, + MessageFormat: It's best practice to accept an Activity parameter to ensure the Event, Tags and/ or Baggage are applied to the Activity you intended., + Category: Activity.Usage, + DefaultSeverity: Warning, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Event] + void ValueCached(); + ^^^^^^^^^^^ + +*/ + Guid_1: (56,6)-(56,17), + Message: It's best practice to accept an Activity parameter to ensure the Event, Tags and/ or Baggage are applied to the Activity you intended., + Severity: Warning, + WarningLevel: 1, + Descriptor: { + Id: TSG3014, + Title: Should accept an Activity to apply the Event/ Tags/ Baggage too, + MessageFormat: It's best practice to accept an Activity parameter to ensure the Event, Tags and/ or Baggage are applied to the Activity you intended., + Category: Activity.Usage, + DefaultSeverity: Warning, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Event] + void RequestingValueFromCache(); + ^^^^^^^^^^^^^^^^^^^^^^^^ + +*/ + Guid_1: (59,6)-(59,30), + Message: It's best practice to accept an Activity parameter to ensure the Event, Tags and/ or Baggage are applied to the Activity you intended., + Severity: Warning, + WarningLevel: 1, + Descriptor: { + Id: TSG3014, + Title: Should accept an Activity to apply the Event/ Tags/ Baggage too, + MessageFormat: It's best practice to accept an Activity parameter to ensure the Event, Tags and/ or Baggage are applied to the Activity you intended., + Category: Activity.Usage, + DefaultSeverity: Warning, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Event] + void CacheHit(int? dataLength); + ^^^^^^^^ + +*/ + Guid_1: (62,6)-(62,14), + Message: It's best practice to accept an Activity parameter to ensure the Event, Tags and/ or Baggage are applied to the Activity you intended., + Severity: Warning, + WarningLevel: 1, + Descriptor: { + Id: TSG3014, + Title: Should accept an Activity to apply the Event/ Tags/ Baggage too, + MessageFormat: It's best practice to accept an Activity parameter to ensure the Event, Tags and/ or Baggage are applied to the Activity you intended., + Category: Activity.Usage, + DefaultSeverity: Warning, + IsEnabledByDefault: true + } + }, + { + Location: /* + [Event] + void CacheMiss(); + ^^^^^^^^^ + +*/ + Guid_1: (65,6)-(65,15), + Message: It's best practice to accept an Activity parameter to ensure the Event, Tags and/ or Baggage are applied to the Activity you intended., + Severity: Warning, + WarningLevel: 1, + Descriptor: { + Id: TSG3014, + Title: Should accept an Activity to apply the Event/ Tags/ Baggage too, + MessageFormat: It's best practice to accept an Activity parameter to ensure the Event, Tags and/ or Baggage are applied to the Activity you intended., + Category: Activity.Usage, + DefaultSeverity: Warning, + IsEnabledByDefault: true + } + } + ] +} \ No newline at end of file diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..0440c8f2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..96135c81 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// Determines if diagnostics are generated for missing activities. Defaults to true. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true, bool generateDiagnosticsForMissingActivity = true) + { + if (string.IsNullOrWhiteSpace(name)) + throw new System.ArgumentNullException(nameof(name)); + + Name = name; + DefaultToTags = defaultToTags; + GenerateDiagnosticsForMissingActivity = generateDiagnosticsForMissingActivity; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; + + /// + /// Determines if diagnostics are generated for when an Activity method does not return an activity, or + /// when an Event or Context method does not include and Activity as a parameter. + /// + public bool GenerateDiagnosticsForMissingActivity { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs new file mode 100644 index 00000000..4ae40357 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#CriticalAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: CriticalAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CriticalAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public CriticalAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs new file mode 100644 index 00000000..6c9b5f28 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#DebugAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: DebugAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class DebugAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public DebugAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs new file mode 100644 index 00000000..92992af8 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ErrorAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: ErrorAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ErrorAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public ErrorAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..eedf0d3b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#EventAttribute.g.verified.cs @@ -0,0 +1,85 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs new file mode 100644 index 00000000..2e71b1d7 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#InfoAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: InfoAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class InfoAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public InfoAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public InfoAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs new file mode 100644 index 00000000..73df38a1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#StatusDescriptionAttribute.g.verified.cs @@ -0,0 +1,30 @@ +//HintName: StatusDescriptionAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#TestTelemetryCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#TestTelemetryCore.Activity.g.verified.cs new file mode 100644 index 00000000..099777c2 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#TestTelemetryCore.Activity.g.verified.cs @@ -0,0 +1,101 @@ +//HintName: TestTelemetryCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +sealed partial class TestTelemetryCore : ITestTelemetry +{ + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.Diagnostics.Activity? Activity(string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return null; + } + + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + + if (activityActivity != null) + { + activityActivity.SetTag("intparam", intParam); + activityActivity.SetTag("boolparam", boolParam); + } + + if (activityActivity != null) + { + activityActivity.SetBaggage("stringparam", stringParam); + } + + return activityActivity; + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("intparam", intParam); + tagsCollectionEvent.Add("boolparam", boolParam); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + activity.AddEvent(activityEventEvent); + + activity.SetBaggage("stringparam", stringParam); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Context(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) + { + if (!_activitySource.HasListeners()) + { + return; + } + + if (activity != null) + { + activity.SetTag("intparam", intParam); + activity.SetTag("boolparam", boolParam); + activity.SetBaggage("stringparam", stringParam); + } + } + +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#TestTelemetryCore.Logging.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#TestTelemetryCore.Logging.g.verified.cs new file mode 100644 index 00000000..76e67497 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#TestTelemetryCore.Logging.g.verified.cs @@ -0,0 +1,41 @@ +//HintName: TestTelemetryCore.Logging.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +sealed partial class TestTelemetryCore : ITestTelemetry +{ + readonly Microsoft.Extensions.Logging.ILogger _logger = default!; + + static readonly System.Action _logAction = Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel.Information, default, "TestTelemetry.Log: intParam: {IntParam}, boolParam: {BoolParam}"); + static readonly System.Func _logScopeAction = Microsoft.Extensions.Logging.LoggerMessage.DefineScope("TestTelemetry.LogScope: intParam: {IntParam}, boolParam: {BoolParam}"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Log(int intParam, bool boolParam) + { + if (!_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) + { + return; + } + + _logAction(_logger, intParam, boolParam, null); + } + + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public System.IDisposable? LogScope(int intParam, bool boolParam) + { + return _logScopeAction(_logger, intParam, boolParam); + } + +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#TestTelemetryCore.Metric.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#TestTelemetryCore.Metric.g.verified.cs new file mode 100644 index 00000000..a5c69cc9 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#TestTelemetryCore.Metric.g.verified.cs @@ -0,0 +1,119 @@ +//HintName: TestTelemetryCore.Metric.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +sealed partial class TestTelemetryCore : ITestTelemetry +{ + System.Diagnostics.Metrics.Meter _meter = default!; + + System.Diagnostics.Metrics.Counter? _counterInstrument = null; + + public TestTelemetryCore(Microsoft.Extensions.Logging.ILogger logger +#if NET8_0_OR_GREATER +, System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + _logger = logger; + InitializeMeters( +#if NET8_0_OR_GREATER + meterFactory +#endif + ); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + void InitializeMeters( +#if NET8_0_OR_GREATER + System.Diagnostics.Metrics.IMeterFactory meterFactory +#endif + ) + { + if (_meter != null) + { + throw new System.Exception("The meters have already been initialized."); + } + +#if NET8_0_OR_GREATER + System.Collections.Generic.Dictionary meterTags = new System.Collections.Generic.Dictionary(); + + PopulateMeterTags(meterTags); +#endif + + _meter = +#if NET8_0_OR_GREATER + meterFactory.Create(new System.Diagnostics.Metrics.MeterOptions("TestTelemetry") + { + Version = null, + Tags = meterTags + }); +#else + new System.Diagnostics.Metrics.Meter(name: "TestTelemetry", version: null); +#endif + +#if !NET7_0 + + System.Collections.Generic.Dictionary counterTags = new System.Collections.Generic.Dictionary(); + + PopulateCounterTags(counterTags); + +#endif + + _counterInstrument = _meter.CreateCounter(name: "counter", unit: null, description: null +#if !NET7_0 + , tags: counterTags +#endif + ); + } + +#if NET8_0_OR_GREATER + + partial void PopulateMeterTags(System.Collections.Generic.Dictionary meterTags); + +#endif + +#if !NET7_0 + + partial void PopulateActivityTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateEventTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateContextTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateLogTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateLogScopeTags(System.Collections.Generic.Dictionary instrumentTags); + + partial void PopulateCounterTags(System.Collections.Generic.Dictionary instrumentTags); + +#endif + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public bool Counter(int counterValue, int intParam, bool boolParam) + { + if (_counterInstrument == null) + { + return false; + } + + System.Diagnostics.TagList counterTagList = new System.Diagnostics.TagList(); + + counterTagList.Add("intparam", intParam); + counterTagList.Add("boolparam", boolParam); + + _counterInstrument.Add(counterValue, tagList: counterTagList); + + return true; + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs new file mode 100644 index 00000000..c2c3ac9a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#TraceAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: TraceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TraceAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public TraceAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TraceAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs new file mode 100644 index 00000000..79b80029 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenNoNamespace_GeneratesTelemetry.DotNet9_0#WarningAttribute.g.verified.cs @@ -0,0 +1,86 @@ +//HintName: WarningAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute used as an alternative to , where the +/// is set to . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class WarningAttribute : System.Attribute +{ + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public WarningAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , + /// optionally the and . + /// + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public WarningAttribute(int eventId, string? messageTemplate = null, string? name = null) + { + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/TestHelpers.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/TestHelpers.cs index 1783421c..4330fd91 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/TestHelpers.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/TestHelpers.cs @@ -158,6 +158,7 @@ public static async Task Verify(GenerationResult generationResult, .UseDirectory("Snapshots") .DisableRequireUniquePrefix() .DisableDateCounting() + .HashParameters() .UniqueForTargetFrameworkAndVersion(typeof(TestHelpers).Assembly) .ScrubInlineDateTimeOffsets("yyyy-MM-dd HH:mm:ss zzzz") // 2024-22-02 14:43:22 +00:00 .AutoVerify(file => diff --git a/src/Purview.Telemetry.SourceGenerator.sln b/src/Purview.Telemetry.SourceGenerator.sln index 17fd48d1..990a04f8 100644 --- a/src/Purview.Telemetry.SourceGenerator.sln +++ b/src/Purview.Telemetry.SourceGenerator.sln @@ -16,6 +16,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".build-system", ".build-system", "{E718023A-6BA1-455B-936C-8EC3FC0D67AF}" ProjectSection(SolutionItems) = preProject + .build-system\BuildVariables.props = .build-system\BuildVariables.props .build-system\Directory.Build.props = .build-system\Directory.Build.props .build-system\Directory.Build.targets = .build-system\Directory.Build.targets EndProjectSection diff --git a/src/Purview.Telemetry.SourceGenerator/Constants.Activities.cs b/src/Purview.Telemetry.SourceGenerator/Constants.Activities.cs index 6501ceaf..b8525969 100644 --- a/src/Purview.Telemetry.SourceGenerator/Constants.Activities.cs +++ b/src/Purview.Telemetry.SourceGenerator/Constants.Activities.cs @@ -40,6 +40,7 @@ public static partial class Activities public static readonly TemplateInfo ContextAttribute = TemplateInfo.Create("Purview.Telemetry.Activities.ContextAttribute"); public static readonly TemplateInfo BaggageAttribute = TemplateInfo.Create("Purview.Telemetry.Activities.BaggageAttribute"); public static readonly TemplateInfo EscapeAttribute = TemplateInfo.Create("Purview.Telemetry.Activities.EscapeAttribute"); + public static readonly TemplateInfo StatusDescriptionAttribute = TemplateInfo.Create("Purview.Telemetry.Activities.StatusDescriptionAttribute"); public static readonly ImmutableDictionary ActivityTypeMap = new Dictionary { { 0, SystemDiagnostics.ActivityKind_Internal }, @@ -49,6 +50,12 @@ public static partial class Activities { 4, SystemDiagnostics.ActivityKind_Consumer } }.ToImmutableDictionary(); + public static readonly ImmutableDictionary ActivityStatusCodeMap = new Dictionary { + { 0, SystemDiagnostics.ActivityStatusCode_Unset }, + { 1, SystemDiagnostics.ActivityStatusCode_Ok }, + { 2, SystemDiagnostics.ActivityStatusCode_Error } + }.ToImmutableDictionary(); + public static TemplateInfo[] GetTemplates() => [ ActivitySourceGenerationAttribute, ActivitySourceAttribute, @@ -56,7 +63,8 @@ public static TemplateInfo[] GetTemplates() => [ EventAttribute, ContextAttribute, BaggageAttribute, - EscapeAttribute + EscapeAttribute, + StatusDescriptionAttribute ]; public static class SystemDiagnostics @@ -66,6 +74,7 @@ public static class SystemDiagnostics public static readonly TypeInfo ActivityEvent = TypeInfo.Create(SystemDiagnosticsNamespace + ".ActivityEvent"); public static readonly TypeInfo ActivityContext = TypeInfo.Create(SystemDiagnosticsNamespace + ".ActivityContext"); public static readonly TypeInfo ActivityKind = TypeInfo.Create(SystemDiagnosticsNamespace + ".ActivityKind"); + public static readonly TypeInfo ActivityStatusCode = TypeInfo.Create(SystemDiagnosticsNamespace + ".ActivityStatusCode"); public static readonly TypeInfo ActivityTagsCollection = TypeInfo.Create(SystemDiagnosticsNamespace + ".ActivityTagsCollection"); public static readonly TypeInfo ActivityTagIEnumerable = TypeInfo.Create("System.Collections.Generic.IEnumerable>"); @@ -78,6 +87,10 @@ public static class SystemDiagnostics public static readonly TypeInfo ActivityKind_Client = TypeInfo.Create(ActivityKind + ".Client"); public static readonly TypeInfo ActivityKind_Producer = TypeInfo.Create(ActivityKind + ".Producer"); public static readonly TypeInfo ActivityKind_Consumer = TypeInfo.Create(ActivityKind + ".Consumer"); + + public static readonly TypeInfo ActivityStatusCode_Unset = TypeInfo.Create(ActivityStatusCode + ".Unset"); + public static readonly TypeInfo ActivityStatusCode_Ok = TypeInfo.Create(ActivityStatusCode + ".Ok"); + public static readonly TypeInfo ActivityStatusCode_Error = TypeInfo.Create(ActivityStatusCode + ".Error"); } } } diff --git a/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.ActivityMethods.cs b/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.ActivityMethods.cs index 26382ecb..21e45ad1 100644 --- a/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.ActivityMethods.cs +++ b/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.ActivityMethods.cs @@ -18,6 +18,7 @@ static void EmitActivityMethodBody(StringBuilder builder, int indent, ActivityBa out var linksParam, out var startTimeParam, out var timestampParam, + out var _, out var _)) { return; diff --git a/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.ContextMethods.cs b/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.ContextMethods.cs index 9a1aa579..54db2e16 100644 --- a/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.ContextMethods.cs +++ b/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.ContextMethods.cs @@ -18,6 +18,7 @@ static void EmitContextMethodBody(StringBuilder builder, int indent, ActivityBas out var linksParam, out var _, out var _, + out var _, out var _)) { return; diff --git a/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.EventMethods.cs b/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.EventMethods.cs index ebca35a9..c0eb44d6 100644 --- a/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.EventMethods.cs +++ b/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.EventMethods.cs @@ -18,13 +18,13 @@ static void EmitEventMethodBody(StringBuilder builder, int indent, ActivityBased out var linksParam, out var startTimeParam, out var timestampParam, - out var escapeParam)) + out var escapeParam, + out var statusDescriptionParam)) { return; } var activityVariableName = activityParam?.ParameterName ?? (Constants.Activities.SystemDiagnostics.Activity + ".Current"); - if (parentContextOrId != null) { logger?.Diagnostic("Parent context/ Id not allowed on event method, only activities."); @@ -76,6 +76,9 @@ static void EmitEventMethodBody(StringBuilder builder, int indent, ActivityBased indent++; var tagsParameterName = tagsParam?.ParameterName ?? "default"; + var exceptionParam = + methodTarget.Parameters.FirstOrDefault(m => m.IsException) + ?? methodTarget.Tags.FirstOrDefault(m => m.IsException); if (methodTarget.Tags.Length > 0) { var tagsListVariableName = "tagsCollection" + methodTarget.MethodName; @@ -216,6 +219,48 @@ static void EmitEventMethodBody(StringBuilder builder, int indent, ActivityBased EmitTagsOrBaggageParameters(builder, indent, activityVariableName, false, methodTarget, false, context, logger); } + var statusCode = methodTarget.EventAttribute?.StatusCode.Value ?? 0; + if (statusCode != 0) + { + builder + .AppendLine() + .Append(indent, activityVariableName, withNewLine: false) + .Append(".SetStatus(") + .Append(Constants.Activities.ActivityStatusCodeMap[statusCode]) + ; + + // Error + if (statusCode == 2) + { + if (statusDescriptionParam != null) + { + builder + .Append(", ") + .Append(statusDescriptionParam.ParameterName) + ; + } + else if (methodTarget.EventAttribute!.StatusDescription.IsSet) + { + builder + .Append(", ") + .Append(methodTarget.EventAttribute!.StatusDescription.Value!.Wrap()) + ; + } + else if (exceptionParam != null) + { + builder + .Append(", ") + .Append(exceptionParam.ParameterName) + .Append("?.Message") + ; + } + } + + builder + .AppendLine(");") + ; + } + builder.Append(--indent, '}'); context.CancellationToken.ThrowIfCancellationRequested(); diff --git a/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.Parameters.cs b/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.Parameters.cs index 05bad8e7..d03410a9 100644 --- a/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.Parameters.cs +++ b/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.Parameters.cs @@ -91,7 +91,8 @@ static bool GuardParameters(ActivityBasedGenerationTarget methodTarget, SourcePr out ActivityBasedParameterTarget? linksParam, out ActivityBasedParameterTarget? startTimeParam, out ActivityBasedParameterTarget? timestampParam, - out ActivityBasedParameterTarget? escapeParam + out ActivityBasedParameterTarget? escapeParam, + out ActivityBasedParameterTarget? statusDescriptionParam ) { activityParam = null; @@ -101,6 +102,7 @@ out ActivityBasedParameterTarget? escapeParam startTimeParam = null; timestampParam = null; escapeParam = null; + statusDescriptionParam = null; var activityParams = methodTarget.Parameters.Where(m => m.ParamDestination == ActivityParameterDestination.Activity).ToImmutableArray(); var parentContextOrIdParams = methodTarget.Parameters.Where(m => m.ParamDestination == ActivityParameterDestination.ParentContextOrId).ToImmutableArray(); @@ -109,6 +111,7 @@ out ActivityBasedParameterTarget? escapeParam var startTimeParams = methodTarget.Parameters.Where(m => m.ParamDestination == ActivityParameterDestination.StartTime).ToImmutableArray(); var timestampParams = methodTarget.Parameters.Where(m => m.ParamDestination == ActivityParameterDestination.Timestamp).ToImmutableArray(); var escapeParams = methodTarget.Parameters.Where(m => m.ParamDestination == ActivityParameterDestination.Escape).ToImmutableArray(); + var statusDescriptionParams = methodTarget.Parameters.Where(m => m.ParamDestination == ActivityParameterDestination.StatusDescription).ToImmutableArray(); if (activityParams.Length > 1) { @@ -217,6 +220,49 @@ out ActivityBasedParameterTarget? escapeParam } } + if (statusDescriptionParams.Length > 1) + { + logger?.Diagnostic("More than one StatusDescription parameter defined."); + + TelemetryDiagnostics.Report(context.ReportDiagnostic, + TelemetryDiagnostics.Activities.DuplicateParameterTypes, + statusDescriptionParams.Where(m => m.Location != null).Select(m => m.Location!), + string.Join(", ", escapeParams.Select(m => m.ParameterName)), + "status description parameters" + ); + + return false; + } + else + { + statusDescriptionParam = statusDescriptionParams.FirstOrDefault(); + if (statusDescriptionParam != null) + { + if (!Utilities.IsString(statusDescriptionParam.ParameterType)) + { + TelemetryDiagnostics.Report(context.ReportDiagnostic, + TelemetryDiagnostics.Activities.StatusDescriptionMustBeString, + statusDescriptionParams.Where(m => m.Location != null).Select(m => m.Location!), + string.Join(", ", escapeParams.Select(m => m.ParameterName)), + "status description parameters" + ); + + return false; + } + + if (methodTarget.MethodType != ActivityMethodType.Event) + { + TelemetryDiagnostics.Report(context.ReportDiagnostic, + TelemetryDiagnostics.Activities.StatusDescriptionParameterInvalidType, + statusDescriptionParams.Where(m => m.Location != null).Select(m => m.Location!), + statusDescriptionParam.ParameterName + ); + + return false; + } + } + } + // There can be only one as it's checked on the // combination of parameter name and type. startTimeParam = startTimeParams.FirstOrDefault(); diff --git a/src/Purview.Telemetry.SourceGenerator/Helpers/PipelineHelpers.Activities.cs b/src/Purview.Telemetry.SourceGenerator/Helpers/PipelineHelpers.Activities.cs index 68c3e263..ac220670 100644 --- a/src/Purview.Telemetry.SourceGenerator/Helpers/PipelineHelpers.Activities.cs +++ b/src/Purview.Telemetry.SourceGenerator/Helpers/PipelineHelpers.Activities.cs @@ -196,6 +196,11 @@ static ImmutableArray GetActivityParameters(IMetho logger?.Debug($"Found escape parameter: {parameter.Name}."); destination = ActivityParameterDestination.Escape; } + else if (Utilities.ContainsAttribute(parameter, Constants.Activities.StatusDescriptionAttribute, token)) + { + logger?.Debug($"Found status description parameter: {parameter.Name}."); + destination = ActivityParameterDestination.StatusDescription; + } else if (Constants.Activities.SystemDiagnostics.Activity.Equals(parameter.Type)) destination = ActivityParameterDestination.Activity; else if (Constants.Activities.SystemDiagnostics.ActivityTagsCollection.Equals(parameter.Type) diff --git a/src/Purview.Telemetry.SourceGenerator/Helpers/SharedHelpers.Activities.cs b/src/Purview.Telemetry.SourceGenerator/Helpers/SharedHelpers.Activities.cs index 0879b125..87b2d1b0 100644 --- a/src/Purview.Telemetry.SourceGenerator/Helpers/SharedHelpers.Activities.cs +++ b/src/Purview.Telemetry.SourceGenerator/Helpers/SharedHelpers.Activities.cs @@ -26,20 +26,19 @@ partial class SharedHelpers AttributeValue? includeActivitySourcePrefix = null; AttributeValue? lowercaseBaggageAndTagKeys = null; - if (!AttributeParser(attributeData, - (name, value) => - { - if (name.Equals("Name", StringComparison.OrdinalIgnoreCase)) - nameValue = new((string)value); - else if (name.Equals("DefaultToTags", StringComparison.OrdinalIgnoreCase)) - defaultToTags = new((bool)value); - else if (name.Equals("BaggageAndTagPrefix", StringComparison.OrdinalIgnoreCase)) - baggageAndTagPrefix = new((string)value); - else if (name.Equals("IncludeActivitySourcePrefix", StringComparison.OrdinalIgnoreCase)) - includeActivitySourcePrefix = new((bool)value); - else if (name.Equals("LowercaseBaggageAndTagKeys", StringComparison.OrdinalIgnoreCase)) - lowercaseBaggageAndTagKeys = new((bool)value); - }, semanticModel, logger, token)) + if (!AttributeParser(attributeData, (name, value) => + { + if (name.Equals("Name", StringComparison.OrdinalIgnoreCase)) + nameValue = new((string)value); + else if (name.Equals("DefaultToTags", StringComparison.OrdinalIgnoreCase)) + defaultToTags = new((bool)value); + else if (name.Equals("BaggageAndTagPrefix", StringComparison.OrdinalIgnoreCase)) + baggageAndTagPrefix = new((string)value); + else if (name.Equals("IncludeActivitySourcePrefix", StringComparison.OrdinalIgnoreCase)) + includeActivitySourcePrefix = new((bool)value); + else if (name.Equals("LowercaseBaggageAndTagKeys", StringComparison.OrdinalIgnoreCase)) + lowercaseBaggageAndTagKeys = new((bool)value); + }, semanticModel, logger, token)) { // Failed to parse correctly, so null it out. return null; @@ -60,7 +59,6 @@ partial class SharedHelpers IGenerationLogger? logger, CancellationToken token) { - AttributeStringValue? nameValue = null; AttributeValue? defaultToTags = null; AttributeStringValue? baggageAndTagPrefix = null; @@ -68,22 +66,21 @@ partial class SharedHelpers AttributeValue? lowercaseBaggageAndTagKeys = null; AttributeValue? generateDiagnosticsForMissingActivity = null; - if (!AttributeParser(attributeData, - (name, value) => - { - if (name.Equals("Name", StringComparison.OrdinalIgnoreCase)) - nameValue = new((string)value); - else if (name.Equals("DefaultToTags", StringComparison.OrdinalIgnoreCase)) - defaultToTags = new((bool)value); - else if (name.Equals("BaggageAndTagPrefix", StringComparison.OrdinalIgnoreCase)) - baggageAndTagPrefix = new((string)value); - else if (name.Equals("BaggageAndTagSeparator", StringComparison.OrdinalIgnoreCase)) - baggageAndTagSeparator = new((string)value); - else if (name.Equals("LowercaseBaggageAndTagKeys", StringComparison.OrdinalIgnoreCase)) - lowercaseBaggageAndTagKeys = new((bool)value); - else if (name.Equals("GenerateDiagnosticsForMissingActivity", StringComparison.OrdinalIgnoreCase)) - generateDiagnosticsForMissingActivity = new((bool)value); - }, semanticModel, logger, token)) + if (!AttributeParser(attributeData, (name, value) => + { + if (name.Equals("Name", StringComparison.OrdinalIgnoreCase)) + nameValue = new((string)value); + else if (name.Equals("DefaultToTags", StringComparison.OrdinalIgnoreCase)) + defaultToTags = new((bool)value); + else if (name.Equals("BaggageAndTagPrefix", StringComparison.OrdinalIgnoreCase)) + baggageAndTagPrefix = new((string)value); + else if (name.Equals("BaggageAndTagSeparator", StringComparison.OrdinalIgnoreCase)) + baggageAndTagSeparator = new((string)value); + else if (name.Equals("LowercaseBaggageAndTagKeys", StringComparison.OrdinalIgnoreCase)) + lowercaseBaggageAndTagKeys = new((bool)value); + else if (name.Equals("GenerateDiagnosticsForMissingActivity", StringComparison.OrdinalIgnoreCase)) + generateDiagnosticsForMissingActivity = new((bool)value); + }, semanticModel, logger, token)) { // Failed to parse correctly, so null it out. return null; @@ -105,21 +102,19 @@ partial class SharedHelpers IGenerationLogger? logger, CancellationToken token) { - AttributeStringValue? nameValue = null; AttributeValue? kind = null; AttributeValue? createOnly = null; - if (!AttributeParser(attributeData, - (name, value) => - { - if (name.Equals("Name", StringComparison.OrdinalIgnoreCase)) - nameValue = new((string)value); - else if (name.Equals("Kind", StringComparison.OrdinalIgnoreCase)) - kind = new((int)value); - else if (name.Equals("CreateOnly", StringComparison.OrdinalIgnoreCase)) - createOnly = new((bool)value); - }, semanticModel, logger, token)) + if (!AttributeParser(attributeData, (name, value) => + { + if (name.Equals("Name", StringComparison.OrdinalIgnoreCase)) + nameValue = new((string)value); + else if (name.Equals("Kind", StringComparison.OrdinalIgnoreCase)) + kind = new((int)value); + else if (name.Equals("CreateOnly", StringComparison.OrdinalIgnoreCase)) + createOnly = new((bool)value); + }, semanticModel, logger, token)) { // Failed to parse correctly, so null it out. return null; @@ -138,21 +133,25 @@ partial class SharedHelpers IGenerationLogger? logger, CancellationToken token) { - AttributeStringValue? nameValue = null; AttributeValue? useRecordExceptionRules = null; AttributeValue? recordExceptionEscape = null; - - if (!AttributeParser(attributeData, - (name, value) => - { - if (name.Equals("Name", StringComparison.OrdinalIgnoreCase)) - nameValue = new((string)value); - else if (name.Equals("UseRecordExceptionRules", StringComparison.OrdinalIgnoreCase)) - useRecordExceptionRules = new((bool)value); - else if (name.Equals("RecordExceptionAsEscaped", StringComparison.OrdinalIgnoreCase)) - recordExceptionEscape = new((bool)value); - }, semanticModel, logger, token)) + AttributeValue? statusCode = null; + AttributeStringValue? statusDescription = null; + + if (!AttributeParser(attributeData, (name, value) => + { + if (name.Equals("Name", StringComparison.OrdinalIgnoreCase)) + nameValue = new((string)value); + else if (name.Equals("UseRecordExceptionRules", StringComparison.OrdinalIgnoreCase)) + useRecordExceptionRules = new((bool)value); + else if (name.Equals("RecordExceptionAsEscaped", StringComparison.OrdinalIgnoreCase)) + recordExceptionEscape = new((bool)value); + else if (name.Equals("StatusCode", StringComparison.OrdinalIgnoreCase)) + statusCode = new((int)value); + else if (name.Equals("StatusDescription", StringComparison.OrdinalIgnoreCase)) + statusDescription = new((string)value); + }, semanticModel, logger, token)) { // Failed to parse correctly, so null it out. return null; @@ -161,7 +160,9 @@ partial class SharedHelpers return new( Name: nameValue ?? new(), UseRecordExceptionRules: useRecordExceptionRules ?? new(), - RecordExceptionEscape: recordExceptionEscape ?? new() + RecordExceptionEscape: recordExceptionEscape ?? new(), + StatusCode: statusCode ?? new(), + StatusDescription: statusDescription ?? new() ); } diff --git a/src/Purview.Telemetry.SourceGenerator/Purview.Telemetry.SourceGenerator.csproj b/src/Purview.Telemetry.SourceGenerator/Purview.Telemetry.SourceGenerator.csproj index 33a8f90e..cd59e20a 100644 --- a/src/Purview.Telemetry.SourceGenerator/Purview.Telemetry.SourceGenerator.csproj +++ b/src/Purview.Telemetry.SourceGenerator/Purview.Telemetry.SourceGenerator.csproj @@ -1,5 +1,4 @@  - netstandard2.0 @@ -45,5 +44,4 @@ - diff --git a/src/Purview.Telemetry.SourceGenerator/Records/ActivityAttributesRecords.cs b/src/Purview.Telemetry.SourceGenerator/Records/ActivityAttributesRecords.cs index 7a151f0c..285d1993 100644 --- a/src/Purview.Telemetry.SourceGenerator/Records/ActivityAttributesRecords.cs +++ b/src/Purview.Telemetry.SourceGenerator/Records/ActivityAttributesRecords.cs @@ -26,5 +26,7 @@ AttributeValue CreateOnly record EventAttributeRecord( AttributeStringValue Name, AttributeValue UseRecordExceptionRules, - AttributeValue RecordExceptionEscape + AttributeValue RecordExceptionEscape, + AttributeValue StatusCode, + AttributeStringValue StatusDescription ); diff --git a/src/Purview.Telemetry.SourceGenerator/Records/ActivityRecords.cs b/src/Purview.Telemetry.SourceGenerator/Records/ActivityRecords.cs index aa2b6a4e..7d7760ae 100644 --- a/src/Purview.Telemetry.SourceGenerator/Records/ActivityRecords.cs +++ b/src/Purview.Telemetry.SourceGenerator/Records/ActivityRecords.cs @@ -70,7 +70,8 @@ enum ActivityParameterDestination Activity, StartTime, Timestamp, - Escape + Escape, + StatusDescription } enum ActivityMethodType diff --git a/src/Purview.Telemetry.SourceGenerator/TelemetryDiagnostics.Activities.cs b/src/Purview.Telemetry.SourceGenerator/TelemetryDiagnostics.Activities.cs index ccb40ac4..bd11a437 100644 --- a/src/Purview.Telemetry.SourceGenerator/TelemetryDiagnostics.Activities.cs +++ b/src/Purview.Telemetry.SourceGenerator/TelemetryDiagnostics.Activities.cs @@ -135,5 +135,21 @@ public static class Activities Category: Constants.Diagnostics.Activity.Usage, Severity: DiagnosticSeverity.Info ); + + public static readonly TelemetryDiagnosticDescriptor StatusDescriptionMustBeString = new( + Id: "TSG3016", + Title: "Status parameter should be string", + Description: "Status descriptions can only be of type string.", + Category: Constants.Diagnostics.Activity.Usage, + Severity: DiagnosticSeverity.Error + ); + + public static readonly TelemetryDiagnosticDescriptor StatusDescriptionParameterInvalidType = new( + Id: "TSG3017", + Title: "Status Description parameters are only valid on Events, not Activity or Context methods", + Description: "The parameters {0} is not valid on Activity or Context methods, only on Events.", + Category: Constants.Diagnostics.Activity.Usage, + Severity: DiagnosticSeverity.Error + ); } } diff --git a/src/Purview.Telemetry.SourceGenerator/Templates/Sources/Activities/EventAttribute.cs b/src/Purview.Telemetry.SourceGenerator/Templates/Sources/Activities/EventAttribute.cs index bb5fc67b..25269c88 100644 --- a/src/Purview.Telemetry.SourceGenerator/Templates/Sources/Activities/EventAttribute.cs +++ b/src/Purview.Telemetry.SourceGenerator/Templates/Sources/Activities/EventAttribute.cs @@ -9,40 +9,62 @@ [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] sealed class EventAttribute : System.Attribute { - /// - /// Generates a new . - /// - public EventAttribute() - { - } + /// + /// Generates a new . + /// + public EventAttribute(System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + { + StatusCode = statusCode; + } - /// - /// Generates a new , specifying the and optionally - /// the property and/ or . - /// - public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) - { - Name = name; - UseRecordExceptionRules = useRecordExceptionRules; - RecordExceptionAsEscaped = recordExceptionAsEscaped; - } + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true, System.Diagnostics.ActivityStatusCode statusCode = System.Diagnostics.ActivityStatusCode.Unset) + : this(statusCode) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } - /// - /// Optional. Gets/ sets the name of the event. If null, empty or whitespace - /// then the name of the method is used. - /// - public string? Name { get; set; } + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } - /// - /// Determines if the event should use OpenTelemetry exception recording rules. - /// - public bool UseRecordExceptionRules { get; set; } = true; + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; - /// - /// Determines if a recorded exception (when is true and an exception parameter exists) - /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) - /// and did not affect the operation. Alternatively, use the to override this value by - /// providing a value dynamically. - /// - public bool RecordExceptionAsEscaped { get; set; } = true; + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; + + /// + /// Optional. Gets/ sets the status code of the event. If status code is + /// the status description is determined using following values in order of precedence: + /// + /// A string parameter with the defined. + /// The property. + /// If none of the above are found the first parameter that is of type , it's property. + /// Null, or no value is specified. + /// + /// + /// Defaults to ." + /// + public System.Diagnostics.ActivityStatusCode StatusCode { get; set; } + + /// + /// Optionally provides a description for the when + /// set to . + /// + public string? StatusDescription { get; set; } } diff --git a/src/Purview.Telemetry.SourceGenerator/Templates/Sources/Activities/StatusDescriptionAttribute.cs b/src/Purview.Telemetry.SourceGenerator/Templates/Sources/Activities/StatusDescriptionAttribute.cs new file mode 100644 index 00000000..2daa8935 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator/Templates/Sources/Activities/StatusDescriptionAttribute.cs @@ -0,0 +1,15 @@ +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events +/// when the status code is set to . +/// +/// Its presence on a parameter will be used as the status description. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class StatusDescriptionAttribute : System.Attribute +{ +}